2022-04-11 02:48 AM
void uartInit()
{
USART_InitTypeDef uartInitStruct;
GPIO_InitTypeDef gpioInitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
gpioInitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
gpioInitStruct.GPIO_Mode = GPIO_Mode_AF;
gpioInitStruct.GPIO_OType = GPIO_OType_PP;
gpioInitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpioInitStruct.GPIO_Speed = GPIO_Speed_Level_1;
GPIO_Init(GPIOA,&gpioInitStruct);
uartInitStruct.USART_BaudRate = 9600;
uartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
uartInitStruct.USART_WordLength = USART_WordLength_8b;
uartInitStruct.USART_Parity = USART_Parity_No;
uartInitStruct.USART_StopBits = USART_StopBits_1;
uartInitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,& uartInitStruct);
}
int main()
{
uint16_t alpha= 'A';
uartInit();
while(1)
{
USART_SendData(USART1,alpha);
USART_SendData(USART1,'\n');
}
}
Solved! Go to Solution.
2022-04-11 06:42 AM
The line should spin waiting for TXE to assert
Did you copy-n-paste it properly? Perhaps you missed the semi-colon?
Alternative would be to check it's empty first
if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == SET)
USART_SendData(USART1, (uint8_t)0x55);
2022-04-11 04:48 AM
Set the correct AF pin mux setting.
Outputs at CMOS levels, not RS232.
Send code not shown.
Clear auto/local variables.
2022-04-11 05:38 AM
sir can you plz explain I am not able get you
2022-04-11 05:56 AM
Which part?
void uartInit()
{
USART_InitTypeDef uartInitStruct = {0};
GPIO_InitTypeDef gpioInitStruct = {0};
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
gpioInitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
gpioInitStruct.GPIO_Mode = GPIO_Mode_AF;
gpioInitStruct.GPIO_OType = GPIO_OType_PP;
gpioInitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpioInitStruct.GPIO_Speed = GPIO_Speed_Level_1;
GPIO_Init(GPIOA,&gpioInitStruct);
/* Connect PXx to USARTx_Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
/* Connect PXx to USARTx_Rx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
uartInitStruct.USART_BaudRate = 9600;
uartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
uartInitStruct.USART_WordLength = USART_WordLength_8b;
uartInitStruct.USART_Parity = USART_Parity_No;
uartInitStruct.USART_StopBits = USART_StopBits_1;
uartInitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,& uartInitStruct);
}
...
while(1)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, (uint8_t)0x55);
}
2022-04-11 06:36 AM
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
if i give USART_FLAG_TXE) == SET i am getting the data.
2022-04-11 06:42 AM
The line should spin waiting for TXE to assert
Did you copy-n-paste it properly? Perhaps you missed the semi-colon?
Alternative would be to check it's empty first
if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == SET)
USART_SendData(USART1, (uint8_t)0x55);
2022-04-11 10:08 PM
this its working sir thank you :D .
2022-04-12 02:35 AM
sir after this i tried sending a string it worked and now i am trying to receive string
i am facing issue could you plz help