dmx input

Post your cool example code here.
Post Reply
octavio
Posts: 44
Joined: Sat Apr 15, 2017 6:41 pm
Location: barcelona
Contact:

dmx input

Post by octavio » Tue Nov 07, 2017 11:50 am

Sample code to read a dmx universe,using a dmx to serial adapter and the usart3 rx pin on the blue pill.

Code: Select all


typedef struct usart_reg_map {
    __io uint32 SR;             /**< Status register */
    __io uint32 DR;             /**< Data register */
    __io uint32 BRR;            /**< Baud rate register */
    __io uint32 CR1;            /**< Control register 1 */
    __io uint32 CR2;            /**< Control register 2 */
    __io uint32 CR3;            /**< Control register 3 */
    __io uint32 GTPR;           /**< Guard time and prescaler register */
} usart_reg_map;

 
#define USART3_BASE                     ((struct usart_reg_map*)0x40004800)

void setup()
{
  Serial2.begin(250000,SERIAL_8N2);  //serial2 is USART3
  USART3_BASE->CR1=0x2024;  //disable transmitter



static unsigned int frindex=0;
byte frame[513]; //usually there is a 0 byte followed by 512bytes of data


extern "C" void __irq_usart3(void) {
  int status,data;
   status=USART3_BASE->SR;
   data=USART3_BASE->DR;
   if(status&2) { 
     frindex=0;return;
    }
    if(frindex++<512) frame[frindex]=(unsigned char) data;
      }
Some changes need to be done on the library to change the default irq handler:

viewtopic.php?f=3&t=2659&p=35275&hilit=octavio#p35275
viewtopic.php?f=3&t=1816&hilit=usart+isr+weak

Post Reply