UART Transmission with atmega328p

For general Flowcode discussion that does not belong in the other sections.
ChrisT66
Posts: 103
http://meble-kuchenne.info.pl
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post 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

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post 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.... :)

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post by ChrisT66 »

Ok, got it. Now I just have to find out why it doesn't work.

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post 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.

mnfisher
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

Post by mnfisher »

Looking at the first word (DC 05)

5 * 256 + 220 == 1500

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post by ChrisT66 »

Yes, of course that is correct for the example. So not a conversion problem but a transmission problem as I get -14884?

mnfisher
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

Post 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

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post 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.

mnfisher
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

Post 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

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: UART Transmission with atmega328p

Post 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

Post Reply