2013-11-17 08:54 PM
hii,
I am using STM32F051K6 for my development. I wrote my won STM Bootlaoder and it Successfully download my test led application in keil. My next Step is USART. to communicate with some Analog Devices before that I Wrote USART driver for that i Configure USART1, Enable NVIC. But whenever i Send a Byte from my Host UI to Controller it Sent Successfully but i got Wrong Rx Byte 0xFF from controller for that i monitored the port continuously. Here is my USART code : void usart_init() { RCC->APB2ENR |= RCC_APB2ENR_USART1EN ;//Enable USART2 Clock RCC->AHBENR |= RCC_AHBENR_GPIOAEN; // Turn on IO Port A GPIOA->MODER |= (GPIO_MODER_MODER9_1 | GPIO_MODER_MODER10_1); // PA9 and PA10 Alternate function mode GPIOA->AFR[1] |= 0x00000110; //Set the alternate functions for PA9 AF1 and PA10 //RCC-> APB2ENR | = RCC_APB2ENR_USART1EN; // Enable clock USART1 // 115200 Bd @ 48 MHz // USARTDIV = 48 MHz / 115200 = 416 = 0x01A0 // BRR [15:4] = USARTDIV [15:4] // When OVER8 = 0, BRR [3:0] = USARTDIV [3:0] USART1->BRR = (48000000/115200);//(uint16_t) (0x01A0); // USART enable // Enable Receiver // Enable Transmitter USART1->CR1 = (uint32_t) (USART_CR1_UE | USART_CR1_RE | USART_CR1_TE); // Default value USART1->CR2 = (uint32_t) (0x00000000); USART1->CR3 = (uint32_t) (0x00000000); //Enable interrupt RXNE USART1->CR1 |= (uint32_t) (USART_CR1_RXNEIE); // Enable interrupts in the NVIC USART1 NVIC_EnableIRQ (USART1_IRQn); NVIC_SetPriority (USART1_IRQn, 1); NVIC_ClearPendingIRQ (USART1_IRQn); } int SendByte(int ch) { while (!(USART1->ISR & USART_ISR_TXE)); USART1->TDR = (ch & 0xFF); return (); } int GetByte(void) { while (!(USART1->ISR & USART_ISR_RXNE)); cmd1_byte = (int)(USART1->RDR & 0xFF); return (cmd1_byte); } i send only one Byte eg. 0x70 to controller, received it and send back to again UI but Rx Byte that i received will be sometimes only 0xFF, sometimes 80,0,40,20,10,1,80,0,40..... so any suggestion?2013-11-18 04:57 AM
No idea what you're doing with the interrupt there. Suggest you simplify the code and send a constant stream of characters ('U' would be good), and then validate the bit timing and symbol formation on a scope.
Be conscious that the CMOS outputs are not at suitable levels for RS232 connectivity. Consider using the library and ensuring the bit/parity/stop modes are set correctly.