Receiving Strings - UART - AVR - C

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

Hi guys.

 

Having a bit of an issue with receiving strings via UART.

 

Using an ATmega8.

Coding in C on Atmel Studio 6.2.

Testing with RS232 terminal software, Termite 3.1. And CP2102 USB to UART converter.

 

My Receive String function code is attached. I have tested my functions to transmit/receive characters, and to transmit strings, using Termite --these behaved as expected, showing that the hardware is setup properly, the RS232 terminal software is functional and the UART functions work.

Now I am requesting the MCU to receive a string from Termite and thereafter transmit the same string back to it.  Termite receives a number of random characters at this point, this result is also attached.

 

Any advice will be deeply appreciated.

 

 

 

Attachment(s): 

This topic has a solution.
Last Edited: Thu. Oct 27, 2016 - 06:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where is string located?

David

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

frog_jr wrote:
Where is string located?

Indeed.  In fact IIRC there was a recent thread on just this:  Declaring a pointer doesn't allocate any space for where it points to.  And if string isn't set to anything, it will point to 0 and start overwriting AVR8 GP registers.  I.e. a "null pointer" problem.

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

theusch wrote:

frog_jr wrote:
Where is string located?

Indeed.  In fact IIRC there was a recent thread on just this:  Declaring a pointer doesn't allocate any space for where it points to.  And if string isn't set to anything, it will point to 0 and start overwriting AVR8 GP registers.  I.e. a "null pointer" problem.

 

Yes Yes this makes sense.

I've changed my code based on your advice by moving the string pointer from a global, to an argument in the function. 

Problem Solved!

 

Thanks guys, 

Change is attached

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
*(string+i) = X;

strange syntax. Most would use:

string[i] = X;

;-)

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

clawson wrote:

 

*(string+i) = X;

 

strange syntax. Most would use:

string[i] = X;

;-)

 

I also like to use the matrix notation instead the later!