• AVR Freaks

LockedHow to receive a char and pass it to string in XC8 using USART?

Author
bard
ElectronicaLibreXC
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2015/07/08 12:14:51
  • Location: Colombia, Bogotá D.C.
  • Status: offline
2017/05/01 06:31:26 (permalink)
0

How to receive a char and pass it to string in XC8 using USART?

I'm doing a project for the university which consists of managing the speed of an engine through a pic, recently implemented an android app and communicated through a bluetooth this app will have a slider, which will control the speed. The problem is that this sliber sends me the data as a string, and in XC8 for example the EUSART_Read (); I store a bit of type char, and I need to store an entire string and then pass it to integer. How would I do it?

Thank you in advance for your help.
#1
CinziaG
die fucking humans
  • Total Posts : 3145
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline
Re: How to receive a char and pass it to string in XC8 using USART? 2017/05/01 06:51:24 (permalink)
+2 (2)
You receive one char after the other, and store them into an array at successive positions. Once the terminator is received (whatever it is), you zero-terminate this array and pass the full array to atoi() function.
 
You can use either Interrupts or Polling for receiving the characters.

in 2018 you signed for your annihilation. in 2019 it will come ;) I promise
my most wonderful creations here
https://www.youtube.com/c...dPFRvtwsbSTXp6Sk6azGOQ
#2
crosland
Super Member
  • Total Posts : 2095
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline
Re: How to receive a char and pass it to string in XC8 using USART? 2017/05/01 06:51:56 (permalink)
0 (4)
I suggest you learn to walk before trying to run. There are plenty of good C text books available. Otherwise you will just be asking for a constant drip-feed of solutions as your problems crop up.
#3
JorgeF
Super Member
  • Total Posts : 3345
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: How to receive a char and pass it to string in XC8 using USART? 2017/05/01 06:55:14 (permalink)
+3 (3)
Hi
 
Store the char in the received sequence in an array.
Terminate the array with a NULL char '\0'.
Then just convert the ASCII codes in that string to a number.
You can also convert char by char as they arrive.
 
What you need to know is the string length or have a special terminating character in the string so that in the PIC side you know when the full string is received.
But, as you have control on the sending side (android app) you can define the protocol details so there are no surprises on either side.
 
HIH
 
Best regards
Jorge
 
#4
JorgeF
Super Member
  • Total Posts : 3345
  • Reward points : 0
  • Joined: 2011/07/09 11:56:58
  • Location: PT/EU @ Third rock from the Sun
  • Status: offline
Re: How to receive a char and pass it to string in XC8 using USART? 2017/05/01 06:58:20 (permalink)
+1 (1)
Hi
crosland
I suggest you learn to walk before trying to run. There are plenty of good C text books available. Otherwise you will just be asking for a constant drip-feed of solutions as your problems crop up.

It looks like the OP already passed that point.
Already put in place an android app, probably its not exactly a programming noob.
 
Just my 2 cents...
 
best regards
Jorge
 
#5
bard
ElectronicaLibreXC
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2015/07/08 12:14:51
  • Location: Colombia, Bogotá D.C.
  • Status: offline
Re: How to receive a char and pass it to string in XC8 using USART? 2017/05/01 07:01:52 (permalink)
0
Thanks for the prompt reply JorgeF and CinziaG, I clarified this doubt, then proceed to store the bit's in an array and then finish reading the data with NULL character and then convert either char to char data or before storing them in the array.
post edited by bard - 2017/05/01 07:06:09
#6
Jump to:
© 2020 APG vNext Commercial Version 4.5