Atmega328 UART code

Hi everyone!

I recently received my 9DOF Razor IMU, equipped with an Atmega328P. I loaded the code from http://code.google.com/p/sf9domahrs/ and it worked properly.

Now I would like to send the data to my main microcontroller, which is a TI F28335, via the UART TX/RX pins. What I would like to do is the following: My TI controller sends an arbitrary bit which triggers the RX interrupt on the atmega. The atmega in turn writes the calculated sensor data back to the TI.

I would like to ask if you could post me some C-code to initialize the Atmega RX interrupt and to clear any interrupt flags when data has been sent or whatever is necessary. I am not familiar with the semantics and would not like to delve into it any deeper than necessary :slight_smile:

Regards, Christoph

P.S. If this is an absolutely stupid idea and you know of a much better way to do it, please let me know!

Not sure why you need TWO microprocessors, but…

The Atmel AVR code you reference is using Arduino, C++. That includes a serial UART library to send/receive at your desired baud rate.

If the TI also has a UART, and if you ensure the voltage levels are the same on both microprocessors (3.3 vs. 5V), then:

Connect the TX on the TI to the RX on the AVR and vice-versa.

Arrange for both to use the same baud rate.

Device some protocol for the two to use; perhaps the TI outputs on the UART a command named “GET” or some such. The AVR receives this, plus an end of line CR or LF. Then it formats an text/ASCII string with the value to be communicated, like “123.456” or some such and send that on the UART.

The AVR Arduino library for the UART receive is interrupt driven. Your code could poll now and then to see if data has come in. Or it can post a call-back routine. Or other ways.

Do this protocol in a carefully thought-out manner so you can add new features easily.

Be sure you really can’t do this with just one microprocessor - as it’s a PITA to intercommunicate, esp. if you need not do so.

Thanks for your help! I managed to get a response from my IMU when I send a character. Now I’m still struggling with the TI-part, which receives only crap, meh …

I need two controllers because I need several ADC’s, PWM’s and such stuff which is not included on the IMU - also, the computational power of the atmega is most likely too low for my application :slight_smile: