USART/UART pass through??

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

I would like to use the two USARTs in the ATtiny1634 so that GPS messages are read in on one port and output unchanged on the other port. On the port that repeats the GPS messages I want to inject other data calculated in the Tiny.

 

Also, the Tiny will send configuration messages to the GPS and receive confirmations from it.

 

I would like to code this in assembly.

 

Any suggestions where to begin?  I did set up a UART many years ago on ATmega8535 (if I recall correctly).

 

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

Well the way you do it is pretty much exactly as you just described. For the RX I'd set up an interrupt so no incoming are lost. Outbound you can just send when ready unless there's some tight timing constraint. If you've done this before then what's the question here exactly? 

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

Go on. You design your program on paper. Then write the appropriate subroutines.
Call the subroutines according to your flowchart.
.
If you post your flowchart, you can ask questions about any blocks you have difficulties with.
.
The logic is the same for any language. The program statements depend on the language. In fact the ASM is pretty similar to the C.
.
David.

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

I don't think there will be any timing constraint, but the calculation part of the Tiny uses the hardware interrupt (INT0) the way I have it now.   I can miss some input data for the Tiny calculation without causing any problem, but I don't want to miss any GPS data (I plan to restrict the GPS data to just one sentence sent at 4800 baud once the Tiny has set up the GPS).    Perhaps I should simplify this project by inputting the GPS data at the higher default rate of the GPS and then sending it out the other UART at 4800 baud??  

 

When I used the UART several years ago, it was just to send whatever I wanted to debug other code.

 

I've made no flow chart for this project yet.

 

Should I just fill a large enough buffer, check to see if the message is the desired one to be forwarded ($GPRMC) and and leave the buffer unchanged to send out the other UART?

 

I think I can parse the buffer to see if the acknowledgements are OK from the GPS (for setup/startup commands).  The GPS I bought has lots of support for Adrino, but it is not in assembly.   Has anyone here used the Featherwing GPS card from Adafruit?

 

 

Last Edited: Sun. May 28, 2017 - 06:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Surely these are the design questions that you must answer yourself? You're the only one who knows what you really want to achieve here. 

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

Sounds like a job for a ring buffer (aka circular buffer or FIFO)  on the input.

 

Then the output can just pick from the FIFO, or inject, as & when it's ready.

 

You may or may not also want a FIFO on the output...

 

I would like to code this in assembly.

As already noted, the design is the important thing; the implementation - whether assembler or whatever - should just drop out from that.

 

But this sounds like the kind of thing to at least prototype in 'C' - then convert to 'C' if required...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's a chunk of code (written in Bascom) where I attempted to passthrough serial communication from Uart1 to Uart4 (and vice versa).  I am trying to go through  an atmega1280.

Anything obvious in this code chunk that I am doing wrong?

 

' specify the used micro
$regfile = "M1280def.dat"
 ' used crystal frequency
$crystal = 7370000
$hwstack = 40                                               ' default use 32 for the hardware stack

$swstack = 40                                               ' default use 10 for the SW stack

$framesize = 40                                             ' default use 40 for the frame space

Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM1:" For Binary As #1
Config Com2 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM2:" For Binary As #2
Config Com3 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM3:" For Binary As #3
Config Com4 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM4:" For Binary As #4

' Serialin3 is keyword for the 4th com port on the Atmel1280
Config Serialin3 = Buffered , Size = 1 , Bytematch = All
Config Serialin2 = Buffered , Size = 1 , Bytematch = All
Config Serialin1 = Buffered , Size = 1 , Bytematch = All
Config Serialin = Buffered , Size = 1 , Bytematch = All

Dim A1 as Byte
Dim B4 As Byte

 

Enable Interrupts

 

Do

               B4 = Ischarwaiting(#4)       '  Onix UART4 = com6 (FTDI chip)  **********************  RESPONSE FROM THE 8266 CHIP *********************

               If B4 = 1 Then                                           'we got something

                  B4 = Waitkey(#4)                                       'get it

                  Print B4            ' Onix Com
                  'Print "B#4 received on Com6"

               End If

               A1 = Ischarwaiting()       ' Onix UART1 = COM8   *************   DATA COMING INTO THE ONIX/ATMEL CHIP FROM THE SERIAL PROGRAMER ************

               If A1 = 1 Then                                           'we got something

                  A1 = Waitkey()                                       'get it

                  Print #4 , A1            ' WiFi UART
                 ' Print #4 , "A#1 received on COM8"

               End If

             
Loop
 

Johnny Ancich

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

There ARE timing constraints, here.

 

Depending on the GPS output sentence structure, there MIGHT not be much space to insert something.

 

Further, you probably want that added information to be at a fixed location within the string of GPS sentences (so that it appears in the same sequential order every time). This probably implies two things: (1) You will need to at least partially parse the sentences so that you know which sentence is being received and where it's end is. That will tell you when to insert your added information. (2) You will need some kind of buffer to store the GPS sentences because there MAY be new sentence data that comes from the GPS as the same time you are trying to output your own data. 

 

I recall that GPS sentences come once a second. So, if the time occupied by the GPS sentences plus the time occupied by your data exceeds one second, then you will have to output at a faster rate than the input.

 

With GPS data going through a buffer you will loose any between sentence spacing. If you need that spacing, then you will need to at least partially parse the data coming out of your buffer to determine sentence ends so that YOU can insert the appropriate between sentence spaces. You will NOT want to use delay functions for this because they are blocking and you won't be able to tolerate that.

 

This will take some careful on-paper design and it is something only YOU (or someone else working on the same project) can reasonably do.

 

Bon Project!

 

Jim

 

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Any reason you are replying to a two year dormant thread Johnny?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Didn't notice the date.  Besides isn't it usually the moderator that is responsible for closing/archiving a dormant thread?

Johnny Ancich

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

threads seem to be never really closed, here. They can be locked, but that seems to be done mostly for either having turned into a flame war or as a cross-post.

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

JohnnyAncich wrote:

Didn't notice the date.  Besides isn't it usually the moderator that is responsible for closing/archiving a dormant thread?

Good question, but we get close to 10,000 threads a year here and determining when a thread has 'expired' is pretty close to impossible.  And in this case a thread from two years ago is so far back in the pages we don't expect it to resurface....usually.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Further, there may be legit reasons for resurrecting an old thread. Unfortunately, it happens most often from someone trying to "answer" an old question in a thread where the original poster is long gone.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

The best approach is to leave all threads open just in case anyone later has anything "useful" to add, however late that may come. The only reason to lock if they are later hijacked in some unconnected way.

 

Personally I commend JohnyAnchich for clearly having searched and appended to some thread that may have relevance to what he's asking. However I would refer him to the previous discussion in the earlier posts. It was suggested that interrupts and ring buffering are used for this. Not synchronous polling as currently seen in the Bascom implementation. So there is something to be learned from the thread. 

 

In fact with multiple UARt involved it's difficult to imagine how this could be done without interrupts/buffers ?

 

One thing I didn't understand if that the text said:

JohnnyAncich wrote:
passthrough serial communication from Uart1 to Uart4 (and vice versa)
but then the code goes on to apparently open FOUR comms channels. Why bother with 2 and 3 if the mirror is only 1<->4 ?? Also what's the purpose of this? The usual reason for such a "pass through" is to monitor or manipulate the data but neither seems to be attempted here - so why the intervening 1280 at all?

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

clawson wrote:
In fact with multiple UARt involved it's difficult to imagine how this could be done without interrupts/buffers ?
DMA

AN_8046 AVR1304: Using the XMEGA DMA Controller

[PDF]

...

• Interrupts upon buffer empty and errors

...

AN_8049 AVR1307: Using the XMEGA USART

 


ATxmega128A1U - 8-bit AVR Microcontrollers

 

"Dare to be naïve." - Buckminster Fuller

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

There is some obsolete code in the sample provided that I should of removed. Sorry.

 

My aim of having my atmel micro act as a serial passthru is due to a peripheral device connected to Uart4 (that can be programmed serially).   Even if I have to reprogram the atmel chip after programming the peripheral device, this prevents having to add a serial port on the board just for the peripheral device.   The peripheral device is programmed serially through an Arduino IDE, and it is expecting serial responses.

 

I agree with using interrupts at least for the data being received back from the peripheral device.   I will try that route next.

Johnny Ancich

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

gchapman wrote:

clawson wrote:

In fact with multiple UARt involved it's difficult to imagine how this could be done without interrupts/buffers ?

 

DMA

AN_8046 AVR1304: Using the XMEGA DMA Controller

[PDF]

...

• Interrupts upon buffer empty and errors

...

AN_8049 AVR1307: Using the XMEGA USART

 


ATxmega128A1U - 8-bit AVR Microcontrollers

 

 

I am using an Atmega1280.

Johnny Ancich

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

If you are still in design infancy maybe take a look at XMEGA.  The pass through could be done in DMA and you could have this in firmware as an option the you select with a jumper or pushbutton thats read at startup.

 

I myself am playing with the peripheral to peripheral feature of the EDMA in a smaller model as well.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Before you accept peripheral to peripheral transfer with no buffer, consider whether or not there is a timeslot somewhat that is guaranteed to hold your added characters.

 

You will also need to do at least some parsing of the GPS data to tell where that timeslot is. Example: if there is an opening after every $GPZDA sentence, the you need to find that sentence when it comes whizzing by, then look for its end. Thus, you cannot, willy-nilly just arbitrarily stick your data into that stream. You will trash the data that is expected to be in a very specific order within every sentence.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

ka7ehk wrote:
Before you accept peripheral to peripheral transfer with no buffer,

In the XMEGA there is block transfer in the DMA, which should take care of that important component

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

I solved my problem! And without the use of interrupts!  The only caveat is that this will not work if you have serial data being transmitted and received at the same time.  Luckily the serial stream just sends, waits for a response before sending another burst.   The code down below was for an Atmega1280.

 

 

 

$regfile = "M1280def.dat"
 ' used crystal frequency
$crystal = 7370000
 
 
 
$hwstack = 32
$swstack = 16
$framesize = 32
 
 
Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM1:" For Binary As #1
 
Config Com4 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "COM4:" For Binary As #4
 
 
Dim Rx_char As Byte
Dim Rx4char As Byte
 
Do
 
   If Ischarwaiting() = 1 Then
 
      Rx_char = Inkey()
     ' Rx_char = Rx_char + 32
      'Uncomment this line to send back lower-case
 
       Printbin #4 , Rx_char
        'if you use just Print then you will get the ascii code number back (3 chars).
                           'e.g.  press z and 122 would come back with Print, but z will come back with Printbin
 
   End If
 
  If Ischarwaiting(#4) = 1 Then
 
      Rx4char = Inkey(#4)
     ' Rx_char = Rx_char + 32
      'Uncomment this line to send back lower-case
 
 
       Printbin Rx4char   'if you use just Print then you will get the ascii code number back (3 chars).
                           'e.g.  press z and 122 would come back with Print, but z will come back with Printbin
 
   End If
 
Loop
 
End ' =========================================================

Johnny Ancich

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

The "caveat" is why you might want to explore interrupts. ;-)

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

OK, I'll bite:  In #7 we learn that a stream into UART1 at 115200 is to be directed to a stream from UART4 at 115200.  Me, I'd skip the $10 Mega1280 and connect the wires together.  Just sayin'.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Me, I'd skip the $10 Mega1280 and connect the wires together. Just sayin'.

 

 

clawson wrote:

Also what's the purpose of this? The usual reason for such a "pass through" is to monitor or manipulate the data but neither seems to be attempted here - so why the intervening 1280 at all?


Agree!

Last Edited: Sat. Mar 30, 2019 - 12:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Give this a read, no programing required

https://www.maximintegrated.com/en/app-notes/index.mvp/id/588