2023-12-08 04:55 AM - last edited on 2023-12-11 02:25 AM by Mike_ST
Hey STMcommunity,
I am trying to implement a Modbus protocol, however the DR register of the USART i am using does not output the correct numbers.
I am sending the following message to the MCU "11 03 00 04 00 04 07 58" (hex numbers) but get the following response "82 00 F8 F5 E3 FE FF E0 D7" (Hex numbers). The returning message should be 13 bytes big which are present in the buffer just before sending.
(keep in mind the values in the picture are decimals)
However the first value which should be 0x11 in the DR register is actually 0x58
The code i am using to write to the DR register is:
void MBSendData(unsigned char count) //Send final data over UART
{
for (unsigned char c=0; c<count;c++)
{
while( !( USART1->SR & (1<<7u) ) ) {}; //wait till transmit buffer is empty
USART1->DR = data_in[c];
}
}
What goes wrong here, am i missing something that i am supposed to do?
2023-12-08 05:58 AM
DR is not a memory address, it's a register interface to the peripheral. You cannot read the values once you write them to DR.
You're trying to send "11 03 00 04 00 04 07 58" (Note that your screenshot differs from this, third value is 8 not 0 for instance). Why are you expecting "82 00 F8 F5 E3 FE FF E0 D7" back exactly?