Page 2 of 6

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 9:23 am
by ChrisT66
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

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 9:26 am
by ChrisT66
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

Posted: Mon Oct 14, 2024 9:51 am
by ChrisT66
Ok, got it. Now I just have to find out why it doesn't work.

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 10:12 am
by ChrisT66
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.

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 10:27 am
by mnfisher
Looking at the first word (DC 05)

5 * 256 + 220 == 1500

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 10:40 am
by ChrisT66
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

Posted: Mon Oct 14, 2024 11:13 am
by mnfisher
Maybe - can you look at the data with a scope? Might be worth printing the individual bytes and seeing what the data looks like?

Martin

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 11:30 am
by ChrisT66
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.

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 11:36 am
by mnfisher
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

Re: UART Transmission with atmega328p

Posted: Mon Oct 14, 2024 12:13 pm
by ChrisT66
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