MOD5441X DMX512 Receiver
Posted: Tue Feb 03, 2015 2:09 pm
I have an application where I need to receive and process a DMX512 byte stream from a show controller. The DMX512 protocol is described here: http://en.wikipedia.org/wiki/DMX512 . I have a DS26LS32CN chip to convert the incoming DMX signal to 0-5V and pass it on to UART1 on my MOD5441X dev board. In the code I'm opening the serial port the standard way and create a task to read the data in the buffer.
I'm seeing the data coming into the buffer, but the values that are reported are what they should be. All of the DMX channel data is set to 0, but the code is reporting 0xFC. I thought I would be able to read the correct data bytes no problem and would have to figure out how to detect the start of the DMX packet. There is a 100usec break in the stream to denote the start of the packet. Any suggestions on what I'm doing wrong and how I can detect that break at the start of the packet?
Code: Select all
SerialClose( SYNCON_PORT_NUMBER ); //close the serial port
syncon_serial_fd = OpenSerial( SYNCON_PORT_NUMBER, 250000, 2, 8, eParityNone ); //reopen the port in interrupt mode
iprintf("->Serial: Syncon Handler Opened on Port %d Successfully!\n", SYNCON_PORT_NUMBER); //report progress
if (OSTaskCreate(serial_in_handler_task, NULL, ( void * ) &serial_in_stack[USER_TASK_STK_SIZE], ( void * ) serial_in_stack, SERIAL_IN_PRIO ) != OS_NO_ERR )
{
iprintf("->**Error Creating Serial In Task**\n");
return 1;
}
Code: Select all
void serial_in_handler_task( void *pd )
{
static unsigned char input_buffer[1024]; //input buffer
if (syncon_serial_fd > 0) //make sure the port opened without any errors
{
while (1){ //continuous loop that blocks on UART read
int bytes_read = ReadWithTimeout(syncon_serial_fd, (char*)input_buffer, 1024, TICKS_PER_SECOND); //read from port
switch (bytes_read){ //switch on return value
case 0: //TIMEOUT
break;
case -1: //ERROR
iprintf("->Serial: Error ** \n");
break;
default: //NORMAL
//iprintf("->Serial: Read %d bytes\n", bytes_read);
process_incoming_bytes(input_buffer, bytes_read); //process incoming bytes
break;
}
}
iprintf("->**TERMINATING SYNCON TASK**\n");
}
else
{
//TODO: Handle the error
}
}
Code: Select all
void process_incoming_bytes(unsigned char byte_buffer[], int bytes_read)
{
for (int i=0; i<bytes_read; i++)
{
char current_byte = byte_buffer[i]; //get byte to be processed
switch (syncon_packet_pointer)
{
default: //receive the payload of the packet
if (current_byte != 0)
{
iprintf("->Serial: Byte %d = %x\n", syncon_packet_pointer, current_byte);
}
if (syncon_packet_pointer != SYNCON_PACKET_LENGTH-1)
{
packet_buffer[syncon_packet_pointer++] = current_byte;
}
else
{
packet_buffer[syncon_packet_pointer] = current_byte;
syncon_packet_count++;
//iprintf("->Serial: Count - %d\n", syncon_packet_count);
syncon_packet_pointer = 0;
}
break;
} // end switch
}
}