Question
USART1 problem to setup without configurator
Hi at everyone,
I need to write a code without the Cube IDE configurator, due to save program memory. I tryed to configure the USAR1, but seem not output on the pin the data streem. Seem that the machine runs because, at the first, I tryed to transmit in polling mode cheching the TXE flag to charge the the TDR register, but not data goes to the pin, but rather, the TX pin seem on high impedence. I forgot something.
Below the USART init :
RCC_CCIPR &= 0xfffffffc; //USART1 clock on system clock
RCC_APBENR2 |= 0x00004000; //USART1 clock enable
RCC_IOPENR |= 0x00000005; //GPIOC clock enable
PORTC_MODER &= 0xefffffff; //set PC14 as alternate function
PORTC_AFRH &= 0xf0ffffff; //set PC14 as TxD function
PORTC_OTYPER &= 0xffffbfff; //PC14 PP mode
USART1_CR1 |= 0x00000001; //USART1 enabled
USART1_CR1 &= 0xefffefff; //8 bit data length
USART1_CR3 = 0x00002000; //DMA disable
USART1_BRR = 0x000001a1; //115200
USART1_CR1 |= 0x00000008; //TX enabled
// USART1_CR1 |= 0x00000004; //RX enabled
The TXD pin is on GPIOC14
then into the main program call every 1 second the follow procedure:
void uart_polling_send(const uint8_t *pData, uint16_t Size, uint16_t Timeout)
{
const uint8_t *pdata8bits;
pdata8bits = pData;
//USART1_CR1 |= 0x00000008; //TX enabled
while(Size > 0U)
{
PORTC_ODR ^= 0x8000;
while((USART1_ISR & 0x00000080) == 0) //check TXE flag
{
//here will manage the timeout
}
USART1_TDR = (uint8_t)(*pdata8bits & 0xFFU);
pdata8bits++;
Size--;
}
while((USART1_ISR & 0x00000040) == 0) //check TC flag
{
//here will manage the timeout
}
}Using the "PORTC_ODR ^= 0x8000;" instuction I can check how many time execute and how is the execution time (using an oscilloscope). Seem works the flow into the procedure, but as I say the peripheral pin not work. Why?
Thank you at all!
Valter
