UART transmission Issue in stm32g4
Hi,
I am working with STM32G4.I am communicating with STM32G4 with other controller through UART communication.
I can able to receive the data from other MCU to STM32G4 all the time but sometimes I can't able to transmit data from stm32g4 to other MCU.I used UART PollForConversion method for development.
I receive the data from other MCU to STM32g4 for every 1sec.
Below is the STM32G4 side code:
uint8_t ocpp_txdata[64];
uint8_t ocpp_rxdata[8];
while(){
HAL_UART_Receive(&huart5,ocpp_rxdata,7, 1000);
uint16_t calculatedCRC;
uint16_t receivedCRC;
if(ocpp_rxdata[0]==0x22)
{
calculatedCRC = HAL_CRC_Calculate(&hcrc,(uint32_t *)&ocpp_rxdata, 4);
receivedCRC=ocpp_rxdata[4]<<8 | ocpp_rxdata[5];
if(calculatedCRC==receivedCRC){
switch(ocpp_rxdata[2])
{
case 0x01:
//trasmit data ocpp_txdata[0] to ocpp_txdata[18]
//ocpp_txdata[16],ocpp_txdata[17] is crc
HAL_UART_Transmit(&huart5, ocpp_txdata,19, 100);
break;
case 0x02:
//trasmit data ocpp_txdata[0] to ocpp_txdata[13]
//ocpp_txdata[11],ocpp_txdata[12] is crc
HAL_UART_Transmit(&huart5, ocpp_txdata,14, 100);
break;
}
}
}
I can able to transmit the data from stm32g4 to other mcu but sometimes I can't.
What I observed is whenever I restated the system and if I remove the power in those cases initially I can't able to transmit.
Can anyone suggest what may be the issue.
I know interrupt mode for UART works better but I have to do with pollforconversion method only.
Thanks
