Receiving RS485 (DMX)

13 Oct 2010

Hi all,

I'm trying to get one of my mbed's to receive data on RS485, specifically that of DMX format. I've got myself a transceiver, but I'm a bit stuck on the coding, largely caused by my lack of knowledge about how the serial port on the mbed actually receives serial data.

In my main function I've got a line formatting the port and that compiles nicely, as well as one setting the correct baud rate. The mbed will need to receive a 513 byte packet and ignore the start code and read three of the following 512 (I'll stick with the first three for the sec) bytes and extract a value. This is where my lack of knowledge comes in.

I defined a variable to hold a value, and then put the following in my main function:

value = dmxin.getc();

with dmxin being the serial port. It compiles happily, but will this just update value with each new byte that comes in? Is there something other than getc I can use that will allow me to focus on, say, byte 2 of the packet?

 

Thanks so much if anyone can help :)

 

Simon

13 Oct 2010

It's probably for DMX you're going to have to get somewhat "closer" to the hardware. Given that the packet start is MAB you'll need to detect the break condition to align the packet reception. A buffered interrupt system to then read the packet would probably work but given the 250k baud rate it's probably a good candidate for using the DMA to transfer the streamed packet directly into a memory buffer which can then be processed while the DMA gets the next packet.

13 Oct 2010

Right, ok. So detect the break, wait until a space of 88uS occurs and then send everything after directly into a buffer?

I'll try and code that somehow...

 

Thanks Andy.

13 Oct 2010

Simon,

I wrote a buffered serial library that handles interrupts into a given tx/rx buffer scheme. By it's nature being a "generic library" it won't solve your problem out of the box. However, it's a good starting point to see how to fill a buffer using interrupts. At least something to look over.

In your case however, you'll probably need to build some application logic into it, eg, handle break, mark, etc. should give you something to look at. I still think a DMA solution maybe better as the packet sizes are pretty fixed and large enough to make sense at 250K baud. If you want some advice on how to setup the DMA in this fashion let me know. I have another "project" (it's rough and not ready) that shows streaming data into an SPI from a flash device using DMA. You could use that as a "skel" starting point also.

13 Oct 2010

The second option certainly sounds better. If I could have a look that'd be great, please.

 

Thanks

14 Oct 2010

If you want to see my code click my name above and look at my profile. The code can be found there.