C-code

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: C-code

Post by mnf »

Hi,

Glad to hear it's receiving ok!
Can you post your code that's giving the errors? I used m ((msg) as an array to receive the data and x (& y) as data to be extracted.

Both were declared as local variables ( hence the '.' at the start) - it's good practice to keep a minimum number of globals to aid readability.

You can output all the data in the message using a loop: - for example to output it to UART. Note that m, i and error are defined as local (m[12] byte, byte and byte) and I don't check error (if .error & 0x80 then something has gone awry)
output.JPG
output.JPG (26.85 KiB) Viewed 19429 times
Martin

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times

Re: C-code

Post by Dutch »

Martin, i did send you an message. can you check if you received it.

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: C-code

Post by mnf »

For completeness:

Combined j1850 - here demo'd as if pin d4 is pulled high acts as receiver else as transmitter....
Not sure if it's worth pulling the code off as a component??
j1850.fcfx
(43.09 KiB) Downloaded 693 times
Note this code is very AVR specific (should work on any Arduino/AVR chip with Timer1) - the timing code is however very localised (start, stop timer and retrieve number of ticks) so it might be possible for some PIC/ARM whizz to convert??


Then I found this-
http://www.interfacebus.com/Automotive_ ... 0_Bus.html which gives a good description of the bus - and I've used an inverse of this from the c above.. Note that the bus may be at 20v so the signal needs to be shifted and inverted to work with the arduino. It would be fairly straightforward to invert the signal - I also don't think the send compiled with the message standard - for example there is no crc - although the code is there..

Martin

Post Reply