Hi Guys!
I am working on a MIDI interface with an Atmega1284P using U(S)ART 0. I have tried to, not enable TXEN0 and toggle the output, works fine, but when I enable the USART0 I can't get it to react (measuring with an oscilloscope) at PD1)). I just seem to stay on +5V.
The initialization is this:
#define F_CPU 20000000UL
#define MIDI_BAUDRATEVAL 31250
void midiInit(){ //set up USART UCSR0B = (1<<TXEN0); UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); //8 bit, 1 stop, no parity // Set the baud rate unsigned int baudrate; baudrate = (((F_CPU / (MIDI_BAUDRATEVAL * 16UL))) - 1); MIDI_UBRRL = (unsigned char) baudrate; MIDI_UBRRH = (unsigned char) (baudrate >> 8); }
This is the execution:
int main(){ ... sendMidiData(0xE0); //controller midi ch0 sendMidiData(0xE5); //random controller number sendMidiData(0xE7); //random value displayValue(test); .... }
Of this:
void sendMidiData(uint8_t midiVal){ while((UCSR0A & (1<<UDRE0)) == 0); UDR0 = midiVal; test++; }
The 'test' value displays fine on my display, and raises by 3 every time I execute the 'sendMidiData()'.
Hope someone can help!
All the best!