cancel
Showing results for 
Search instead for 
Did you mean: 

DR register outputs incorrect numbers STM32F407VG

Jordi_
Associate

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.

Jordi__0-1702039723989.png

(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

Jordi__1-1702039866039.png

 

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?

1 REPLY 1
TDK
Guru

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?

 

If you feel a post has answered your question, please click "Accept as Solution".