Serial comm lib

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for the noob-ish question. I may be missing somethign obvious.

I'm progressing with my move to non-arduino AVR development on linux using eclipse. One of the things that seems to be missing is serial IO library. I have the basics down, but see no point in building my own lib from scratch. I'm sure I'd do it poorly.

I did find several reference to P. Fleury in my searches, but there seems to be issues with his lib on newer uC like the 328p. Is there a gcc lib I'm missing that implements serial IO?

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

but there seems to be issues with his lib on newer uC like the 328p

Hardly - easily fixed if you have a device his old(5 years+) code does not support. See below.

There is Pascal Stang's Procyon avrlib as an alternative. But you are going to find the same - it dates from a few years ago and won't necessarily have support for all models either.

In Fleury's uart.c near the top you find a huge #if statement. The bit relevant to 48/88/168/328 is currently this:

#elif defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega48P__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) \
 || defined(__AVR_ATmega3250__) || defined(__AVR_ATmega3290__) ||defined(__AVR_ATmega6450__) || defined(__AVR_ATmega6490__)
 /* ATmega with one USART */
 #define ATMEGA_USART0
 #define UART0_RECEIVE_INTERRUPT   USART_RX_vect
 #define UART0_TRANSMIT_INTERRUPT  USART_UDRE_vect
 #define UART0_STATUS   UCSR0A
 #define UART0_CONTROL  UCSR0B
 #define UART0_DATA     UDR0
 #define UART0_UDRIE    UDRIE0

Actually that appears to already have support for 328P in fact. But let's say you needed 328PA support (is there such a thing?) then you would check the io.h to find out what the compiler defined symbol for Atmega328PA was (I suspect it would be __AVR_ATmega328PA__ in fact) then you just edit the list above to add it to the other devices in that "family" (having first ensured by a datasheet comparison that the registers/bits are still called things like UCSR0A, UDRIE0 and so on).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sold!

I thought I was making it harder than it looked, but I've been bitten by way to many things with the latest round of Linux changes (new tome not the rest of the world) that I guess I'm a little gun shy.

I'll give it a shot.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yep. Works with 328p as is.

Thanks again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been doing the Eclipse/AVR thing too... for ATtinys though. Glad you got some help. I, too, will be digging around looking for libs so I don't have to reinvent the wheel. :) Best of luck. I will help if I can.

It should work - bot-thoughts.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

shimniok,

I'm looking to move toward ttiny eventually. I have a few of these from when I didn't see any point of not using arduino. Now that my project has grown...

Let's just say they are not going to waste.