Values such as 21980, 1500, 22460, -14488, 21980, -5149, 1500, 2000 etc. are currently displayed. The values are always the same, they just change in sequence with each run.
The two data bytes should always result in values between 1000 and 2000.
Chris
UART Transmission with atmega328p
-
- Posts: 103
- http://meble-kuchenne.info.pl
- Joined: Mon Dec 07, 2020 12:47 pm
- Been thanked: 1 time
Re: UART Transmission with atmega328p
I think I need to understand your conversion first (it will take some time). You're a real pro and I'm the opposite.... 

Re: UART Transmission with atmega328p
Probably still a conversion problem.
If I send 2000 in the 1st data record, -15384 is displayed, if I send 1000 then -14384.
In the 2nd record with 2000 sent -11288 and with 1000 then -10288.
In the 3rd record, 22480 is sent at 2000 and then 21480 at 1000.
The difference is always correct at 1000.
If I send 2000 in the 1st data record, -15384 is displayed, if I send 1000 then -14384.
In the 2nd record with 2000 sent -11288 and with 1000 then -10288.
In the 3rd record, 22480 is sent at 2000 and then 21480 at 1000.
The difference is always correct at 1000.
Re: UART Transmission with atmega328p
Yes, of course that is correct for the example. So not a conversion problem but a transmission problem as I get -14884?
Re: UART Transmission with atmega328p
The transmitted data looks correct on the oscilloscope. A logic analyser would be better, but I don't have one.
However, since I am only interested in the changes in the values, perhaps I can simply normalise the incorrect value for 1500 as ‘1500’ and then calculate the differences.
However, since I am only interested in the changes in the values, perhaps I can simply normalise the incorrect value for 1500 as ‘1500’ and then calculate the differences.
-
- Valued Contributor
- Posts: 1628
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: UART Transmission with atmega328p
Can you post the actual values received? It might be a 'sign' extension trick being played on us...
try:
.lsb = payload[.i *2]
.msb = payload[.i * 2 + 1]
.dataRcd[.i] = (.msb << 8) + .lsb
Where .lsb and .msb are local 16 bit unsigned values.
Martin
try:
.lsb = payload[.i *2]
.msb = payload[.i * 2 + 1]
.dataRcd[.i] = (.msb << 8) + .lsb
Where .lsb and .msb are local 16 bit unsigned values.
Martin
Re: UART Transmission with atmega328p
Here are the values:
0= -14884
1= -10796
2= 22480
3= -15384
4= -10788
5= 21980
6= -14884
7= -10788
8= 21980
9= -14884
10= -10788
11= 21980
12= 1500
13= 2000
14= -5149
0= -14884
1= -10796
2= 22480
3= -15384
4= -10788
5= 21980
6= -14884
7= -10788
8= 21980
9= -14884
10= -10788
11= 21980
12= 1500
13= 2000
14= -5149