AS7 Arduino and serial library

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

Hi. Using AS7 and an Arduino (Uno), I want to use the USB serial connection.  I have been on youtube looking at extensive tutorials by Craig Hollinger.

He gives good samples and also the sample code in Github, but not so for the uart.c and uart.h library that he adopts.

Help?

 

Regards JC......

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

Not entirely sure what it is you are asking. If you mean just the Arduino board but programmed in plain C/C++ then isn't it as simply as:

UART_init(void) {
    UCSR0B = (1 << TXEN); // switch on for transmit
    UBRR0 = 103; // value in datasheet for 9600 on 16MHz
}

UART_putchar(char c) {
    while (!(UCSR0A & (1 << UDRE0)));
    UDR0 = c;
}

UART_putstring(char * str) {
    while (*str) {
        UART_putchar(*str++);
    }
}

int main(void) {
    UART_init();
    while(1) {
        UART_putstring("hello\n");
    }
}

 

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

The Uno R3 board has a separate 16U2 processor as a USB/serial bridge. But the main 328P doesn't 'know' that, or that it's connected to a USB port, just as if you attached an external USB/serial adaptor to its TXD/RXD pins.

 

So, forget USB and program the 328P's UART as usual. It will work regardless of whether you use the onboard bridge, an external bridge, or a connection to a traditional PC serial port.

 

Uno R3 schematic: https://content.arduino.cc/asset...

 

 

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


jmclifford@aanet.com.au wrote:

I have been on youtube looking at extensive tutorials by Craig Hollinger.

He gives good samples and also the sample code in Github, but not so for the uart.c and uart.h library that he adopts.

I'm not sure I follow that point either? If I go to:

 

then, yeah there is this "going-beyond-arduino" but as soon as I look into that I see the files you mean but if I pick one at random then the first I happened to pick was "pointers.c" and the first thing I notice there is:

 

 

so virtually the very first this this code starts doing is using a UART. So clearly this chap DOES have some working UART code so back at:

 

 

the next most obvious looking place I see is "AVR" with the promise of "Driver code for ATMEGA" and lo and behold:

 

 

So there is the "UART" stuff you need. In fact in that UART directory you find uart.c and it has:

 

 

which is a kind of souped-up version of what I showed in #2 (actually I personally don't like string output using array rather than pointer syntax because of the index restriction but I guess that's a personal choice?).

 

So yer man Hollinger does appear to have all you need anyway. It's just a case of "cherry picking" the pieces from all over the GitHub.

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

Hi. 

Thank you clawson.  I was expecting all information to be below "going-beyond-adruino".

 

I have since loaded the uart.c and uart.h to my library (folder), and linked to from my project.

I had to comment out the line below in uart.h.

/* uint8_t uart_write_P(uint8_t length, PGM_P buf); */

 

The type PGM_P gave compile issues.

 

Regards JC.....

 

 

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

jmclifford@aanet.com.au wrote:
The type PGM_P gave compile issues.
I think it was deprecated. It was relying on an undocumented feature where an __attribute__ was applied to a typedef I seem to remember.

 

The code would work the same (I believe) if PGM_P in the function interface were simply "void *".