0
\$\begingroup\$

I'm using an ATMEGA328, with an external 20MHz crystal and fuses set by avrdude as -U lfuse:w:0x46:m -U hfuse:w:0xdf:m. I want to send DMX with it. Using the code from Radig Ulricht:

/*------------------------------------------------------------------------------
 Copyright:      Radig Ulrich  mailto: mail@ulrichradig.de
 Author:         Radig Ulrich
 Remarks:        
 known Problems: none
 Version:        17.12.2011
 Description:    DMX_TX


 Dieses Programm ist freie Software. Sie können es unter den Bedingungen der 
 GNU General Public License, wie von der Free Software Foundation veröffentlicht, 
 weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder 
 (nach Ihrer Option) jeder späteren Version. 

 Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, 
 daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, 
 sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT 
 FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License. 

 Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 
 Programm erhalten haben. 
 Falls nicht, schreiben Sie an die Free Software Foundation, 
 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
------------------------------------------------------------------------------*/

#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>

#define F_CPU 20000000
#include <util/delay.h>

#define DMX_BAUD 250000
#define DMX_BAUD_BREAK 80000

volatile unsigned char dmx_buffer[512];

//############################################################################
//DMX Senderoutine
ISR (USART_TX_vect)
//############################################################################
{
    static unsigned int  dmx_channel_tx_count = 0;
    static unsigned char dmx_tx_state = 0;

    switch (dmx_tx_state)
    {
        case (0):
            UBRR0   = (F_CPU / (DMX_BAUD_BREAK * 16L) - 1);
            UDR0 = 0; //RESET Frame
            dmx_tx_state = 1;
            break;

        case (1):
            UBRR0   = (F_CPU / (DMX_BAUD * 16L) - 1);
            UDR0 = 0; //Start Byte
            dmx_tx_state = 2;
            break;

        case (2):
            _delay_us(10);
            //Ausgabe des Zeichens
            UDR0 = dmx_buffer[dmx_channel_tx_count];
            dmx_channel_tx_count++;

            if(dmx_channel_tx_count == 512)
            {
                dmx_channel_tx_count = 0;
                dmx_tx_state = 0;
            }
            break;
    }
}

//############################################################################
//Hauptprogramm
int main (void) 
//############################################################################
{  
    //Init usart DMX-BUS
    UBRR0   = (F_CPU / (DMX_BAUD * 16L) - 1);
    DDRD |= (1<<PIND1); //Output TXD Pin ATmega88
    UCSR0B|=(1<<TXEN0)|(1<<TXCIE0); // TXEN0 Transmitter enable / TXCIE0 TX complete interrupt enable 
    UCSR0C|=(1<<USBS0); //USBS0 2 Stop bits 
    sei();//Globale Interrupts Enable
    UDR0 = 0;//Start DMX

    //Endlosschleife
    while(1)
    {
        dmx_buffer[0]=255;
        dmx_buffer[1]=255;
        dmx_buffer[2]=255;
        dmx_buffer[3]=255;
        dmx_buffer[4]=0;
        dmx_buffer[99]=128;
        dmx_buffer[511]=128;
    }
}

This code produces me a constant and periodic square wave on the TX pin, not the expected dmx packet with the break times and all... What could be wrong?

EDIT: Scope images

enter image description here

enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Can you grab some oscilloscope images for us, please? \$\endgroup\$ Feb 16 '19 at 19:58
  • \$\begingroup\$ As I wrote, it is just a constant periodic squarewave, no differences in the period whatsoever \$\endgroup\$
    – Rando Hinn
    Feb 16 '19 at 20:01
  • 1
    \$\begingroup\$ @RandoHinn Scope images give us more information than that, though. Like the frequency of it, for instance. \$\endgroup\$
    – Hearth
    Feb 16 '19 at 20:13
  • \$\begingroup\$ @Hearth edited Q with images \$\endgroup\$
    – Rando Hinn
    Feb 16 '19 at 20:19
  • \$\begingroup\$ @ElliotAlderson Tagging you to let you know there's an image now too. \$\endgroup\$
    – Hearth
    Feb 16 '19 at 20:20
0
\$\begingroup\$

It looks like you are trying to observe a 250000 baud signal with a scope sampling rate of 250ksps...that's not going to give you anything useful. You should be seeing pulses as narrow as 4us. Try reducing the horizontal time/division to 10us or so.

\$\endgroup\$
1
  • \$\begingroup\$ Will update with proof that it is still the same square wave there that does not show any resemblance to a DMX packet. \$\endgroup\$
    – Rando Hinn
    Feb 19 '19 at 7:07
0
\$\begingroup\$

Fixed by actually using the correct fuse settings on the AVR, crystal-timings wize.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.