Menu

DMX protocol, Q about motogeeks code

louie
2018-04-10
2019-12-27
  • louie

    louie - 2018-04-10

    Hello everyone and a BIG THANX to motogeek for posting this: http://gcbasic.sourceforge.net/Typesetter/index.php/Driving-a-bunch-of-relays-using-one-pin-on-pic
    but i have a question about one line in his code where he specifies the serial comm parameters for his processor:
    "TXSTA = 0b01100101 ' 9 bit data (TX9 = 1), TXEN = 1, high speed (BRGH = 1), place for 9th bit = 1 (TX9D = 1)"
    he is saying 9 bit data, but wikipedia says:
    "At the datalink layer, a DMX512 controller transmits asynchronous serial data at 250 kbit/s. The data format is fixed at one start bit, eight data bits (least significant first[7]), two stop bits and no parity."
    since it's clear that his code works, i wanna know what to specify for an atmega2560 so i'll get the same serial pattern.
    thanx, mike

     

    Last edit: louie 2018-04-12
  • mmotte

    mmotte - 2018-04-10

    This took a little ferreting out but i think this is the solution.
    DMX asynch serial is as you pointed out 250kb &"one start bit, eight data bits (least significant first[7]), two stop bits and no parity".
    PIC's don't do parity with anything built in, GCB has Not implemented parity yet on the HSer. The 9th bit is turned on in motogeeks code, so why? Well, above we said we needed 2 stop bits. so the 9th bit is acting as a stop bit.

    2560 can also do 9 bits but a nice feature of the 2560 usart is ability to do 2 stop bits. Look at the UCSRnC register bit #3 . In GCB to turn that bit on in config just use

    USBS1 = 1      ' turns on 2 stop bits
    

    The 1 in the bit name USBS1 is the channel. 2560 has 4 channels 0,1,2,3. choose wisely.
    Replace:
    "RCSTA = 0b01010000 ' serial port disabled (SPEN = 0), 9 bit data (RX9 = 1) not sure if needed here in RX
    TXSTA = 0b01100101 ' 9 bit data (TX9 = 1), TXEN = 1, high speed (BRGH = 1), place for 9th bit = 1 (TX9D = 1)"
    with
    USBS1 = 1
    baud rate should be calculated fine.
    Your not doing any receive so leave it default.

    GL
    Mike

     
  • mmotte

    mmotte - 2018-04-10

    I see one more thing. motogeek is enabling and disabling the HSer port in the transDMX sub.

    RCSTA.SPEN = 1                'enable USART
    
    RCSTA.SPEN = 0                'disable USART
    

    I would try with these commented out.

    but if you need them then on the 2560 TXEN1 is the bit to set and reset. here again in the name TXEN1 the 1 is the serial port (0,1,2,3).

    TXEN1 =1
    
    TXEN1 =0
    

    GL
    Mike

     
  • Moto Geek

    Moto Geek - 2018-04-11

    Hi mmotte, I enable and disable the uart so I can make the long break using the same TX pin. The long break indicates the start of the DMX sequence. This was the only way I could think of to do that.

     
  • louie

    louie - 2018-04-13

    Hello guys i'm recovering from the flu.
    thanx for clearing it up.
    i'm doing this to configure the parameters:
    UCSR0C = 0b00001011 ' Async, no parity, 2 stop bits, 8 bits

    is this: TXEN0 = 0
    the same as this?: UCSR0B = UCSR0B and 0b11110111 ' disable TX, since the TXEN is bit 3

    and i have to use port0 because my shield is wired to that port. and the shield has jumpers on it so i can disconnect lines TX0 and RX0 when i'm connecting usb.

     

    Last edit: louie 2018-04-13
  • mmotte

    mmotte - 2018-04-14

    UCSR0C = 0b00001011 ' Async, no parity, 2 stop bits, 8 bits
    Looks right

    is this: TXEN0 = 0
    the same as this?: UCSR0B = UCSR0B and 0b11110111 ' disable TX, since the TXEN is bit 3
    Is the same. But TXEN0 = 0 is easier, thankyou compiler for raising us up.

    GL
    Mike

     
    • louie

      louie - 2018-04-14

      yeah that's a nice touch. thanx

       

Log in to post a comment.