CAN to MP3(UART)

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
hoozamawhatsit
Posts: 7
Joined: Sat Apr 11, 2020 3:58 pm
Location: Blue Mountains, Australia
Contact:

CAN to MP3(UART)

Post by hoozamawhatsit »

Hi All,
long time user, first time poster

I need help with idea's on how to program a CAN based MP3 player, this will be used as an announcement system with triggers from CAN with up to 64 messages able to be played.
i have at my disposal;
FC8 Pro ( i decided to upgrade from FC6 a few days ago)
PIC18F2480 or 4480 using internal OSC, currently running at 8Mhz
MCP2562 interface to the CAN BUS
DFRobot Gravity UART MP3, the noise maker.

I am ok at basic programs and proficient with electronic hardware/circuits, i have figured out how to send info on UART(no need to receive) and tested on hardware.
I am having trouble understanding how the CAN component works in FC, i've searched the forums, looked at several other programs etc etc,and now more confused.

In my head i have, IF CANMSG 0x200???? received, send 0xaa 0x07 on UART but i'm not sure how to do that.

Questions;
1. When a CAN message is received into buffer does it mean that the message is there until i retrieve it or is it overwritten when i receive another message?
2. How many messages can be in the buffer at any one time if they are not overwritten?
3. How do i tell a certain CAN message to send a UART message, LUT????
4, If LUT is the go, how the hell do they work?

appreciate any guidance

Cheers,
hooz

User avatar
Benj
Matrix Staff
Posts: 15219
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4763 times
Been thanked: 4299 times
Contact:

Re: CAN to MP3(UART)

Post by Benj »

Hello Hooz,

Welcome to the forums. Sounds like an interesting project and congrats on your purchase.

1. When a CAN message is received into buffer does it mean that the message is there until i retrieve it or is it overwritten when i receive another message?

Some devices work differently and may queue up messages in RAM. Other devices may not have a buffer and it may be a case of servicing messages as they arrive. As long as there are no major delays in your program it should be fairly easy to poll the CAN for incoming messages. You can also filter incoming messages by ID so you only receive messages that you are interested in.

2. How many messages can be in the buffer at any one time if they are not overwritten?

Again this is device dependant. The PIC18F2480 states a double buffered system. That probably means you can have one received packet while you are reading while actively receiving a second packet.

3. How do i tell a certain CAN message to send a UART message, LUT????

I've made a simple example for you.

4, If LUT is the go, how the hell do they work?

Look up table might not be the way to go, this allows you to store fixed data into ROM. You might want a circular buffer as this allows variable data to flow in and out of a buffer in a first in first out type arrangement. I've added the circular buffer to the example for you so you can see how to send data without blocking the incoming CAN messages while you send out the data.

CAN_UART.fcfx
(15.13 KiB) Downloaded 69 times

hoozamawhatsit
Posts: 7
Joined: Sat Apr 11, 2020 3:58 pm
Location: Blue Mountains, Australia
Contact:

Re: CAN to MP3(UART)

Post by hoozamawhatsit »

Hi Benj,

thanks for the informative reply mate, very much appreciated, i'll give it a go.

hoozamawhatsit
Posts: 7
Joined: Sat Apr 11, 2020 3:58 pm
Location: Blue Mountains, Australia
Contact:

Re: CAN to MP3(UART)

Post by hoozamawhatsit »

Hi,

i have spent a little bit of time on figuring out what data i need to program into this CAN_UART_MP3 as it will be a direct replacement for a no longer available device.
CAN_MP3_hack.pdf
(135.89 KiB) Downloaded 67 times
So now i need to figure out how the CAN filter works, once again i am confused.
In my world CAN ID is the device, data is the 8 bytes of information received or sent(Standard).(i've been spoilt for so long with easy software setups)
TH_MP3_Snip.pdf
(90.72 KiB) Downloaded 61 times
The CAN ID for the MP3 player needs to be 0x200 as the device driving it is pre-programmed this way, and there are other devices on the CANbus so i need to filter out the other messages.

There are 8 bytes of data that i can access;
B0 audio files 1 to 8
B1 audio files 9 to 16
B2 audio files 17 to 24
B3 audio files 25 to 32
B4 audio files 33 to 40
B5 audio files 41 to 48
B6 priority 1 to 5 (not needed)
B7 volume control (not needed)

I was thinking of creating a new tab for each byte and mask/filter according to what is required with said tab, is this possible and how do i do it?
Am i wasting my time trying it this way?
Am i overthinking what i need to do?
Once i Mask and filter in the CAN component properties can i filter again in the flowchart so i'm only looking at certain bytes?
e.g. on a switch icon with 8 branches Decision 1 B0>0, decision 2 B1>0, etc etc

Thanks,
Hooz
Attachments
CAN_UART_MN.fcfx
(45.08 KiB) Downloaded 59 times

hoozamawhatsit
Posts: 7
Joined: Sat Apr 11, 2020 3:58 pm
Location: Blue Mountains, Australia
Contact:

Re: CAN to MP3(UART)

Post by hoozamawhatsit »

Finally I've been able to spend a few hours on this today and it all works as expected.
Also put together my prototype to see if there was any noise induced by the environment it'll work in, all seems good so far.

I still haven't figured out how to use the mask/filter settings properly...

Any advice or improvements to my program are very welcome

I'll finish this one off this week by making it a bit more compact and send it off for testing and compliance, then i'll move onto the next CAN based project next week which will save me about 8kg in wiring and halve the current consumption.

thanks Benj for pointing me in the right direction on this project, i'm sure i'll have more questions on the next project.

Cheers,
Hooz
Attachments
IMG_2786.jpg
IMG_2786.jpg (79.64 KiB) Viewed 1178 times
IMG_2785.jpg
IMG_2785.jpg (145.31 KiB) Viewed 1178 times
CAN_UART_2480_v1.fcfx
(132.14 KiB) Downloaded 60 times

User avatar
Benj
Matrix Staff
Posts: 15219
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4763 times
Been thanked: 4299 times
Contact:

Re: CAN to MP3(UART)

Post by Benj »

Hello,

This doc might help, it's our E-blocks CAN course, page 61 onwards should give you an explaination and some worked examples.
https://www.matrixtsl.com/resources/fil ... %20Bus.pdf

Also more here though it looks like it's very similar text.
https://www.matrixtsl.com/wiki/index.ph ... nd_Filters

Prototype looks great :D

hoozamawhatsit
Posts: 7
Joined: Sat Apr 11, 2020 3:58 pm
Location: Blue Mountains, Australia
Contact:

Re: CAN to MP3(UART)

Post by hoozamawhatsit »

haha, i was thinking way too technically with the mask/filter thing, it's all about message ID and nothing to do with the actual data needed to be gathered for the particular ID.
All i needed to read was 26.2.1 on pg 61 of the E-Block CAN course, i had read through the wiki several times which confused me with mentioning data.
Maybe worth adding the mentioned paragraph to the wiki to possibly save others any confusion.

thanks again Benj

hoozamawhatsit
Posts: 7
Joined: Sat Apr 11, 2020 3:58 pm
Location: Blue Mountains, Australia
Contact:

Re: CAN to MP3(UART)

Post by hoozamawhatsit »

Hi Benj and anyone else that can help

Help Please

I have been delayed heaps with this project due to this Covid crap and am now back on track.

I have found an issue with CAN RX only receiving the correct data on the first 2 bits.

It seems exactly the same as this post
https://www.matrixtsl.com/mmforums/view ... +component
where the CAN_CAL.c file had to be fixed

Thanks in advance

Post Reply