MM32F103 lighting and serial port experiment[Copy link]
This post was last edited by serialworld on 2018-10-30 20:21 Use arm-gcc compiler and TrueStudio IDE integrated development environment. Directly use the startup file and connection file of STM32F103, refer to the DEMO program downloaded from the MM32 official website, and make simple modifications. When using the STM32 startup file, pay attention to the different naming of the interrupt function and the MM32 library function. For example: the serial port interrupt function STM32 definition: void USART1_IRQHandler(void), while MM32 is defined as void UART1_IRQHandler(void), and the corresponding startup file needs to be modified. include "delay.h" #include "sys.h" #include "led.h" #include "key.h" #include "uart.h" #include "uart_nvic.h" #include
#include
int _write(int32_t fd, char* ptr, int32_t len) { if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { int32_t i = 0; while (i < len) { while (UART_GetFlagStatus(UART1, UART_IT_TXIEN) == RESET); UART_SendData(UART1, (uint8_t) ptr[i++]); // usart_data_transmit(EVAL_COM1, (uint8_t) ptr[i++]); // while (RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE)) // ; } } return len; } int main(void) { u8 t=0; u8 len; u16 times=0; delay_init(); //Delay function initialization LED_Init(); //Initialize the hardware interface connected to the LEDKEY_Init(); //Initialize the hardware interface connected to the keyLED2=0; //Light up the LED // uart_initwBaudRate(115200u); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// Set the interrupt priority group 2 uart_nvic_init(115200); //Initialize the serial port to 115200 while(1) { // t=KEY_Scan(0); //Get the key value if(UART_RX_STA&0x8000) { len=UART_RX_STA&0x3fff; //Get the length of the data received this time printf("\r\n your message is \r\n"); for(t=0;t