Transfer integer from dsPIC to PC

Status
Not open for further replies.

Dsp121

New Member
Is it possible to transmit an integer value from a micro-controller to a PC or to another micro-controller using UART without converting the integer to character/string in ASCII?


Thanks for any help.
 
The meaning of bits sent over a serial link are just bits. There meaning is up to the guy who writes the code.

But if you want to use integers greater then 8 bits you will have to create a protocol to determine where numbers start and end because common UARTs send a byte at a time.

I am guessing that you want to do this to improve the data you can squeeze through a serial line. If you are using RS232 use USB instead.
 
What I'm doing is to convert the integer to ASCII character before transmitting, but the conversion process is taking too much time to perform. So I was thinking of transmitting directly as integer. What I'm using is a dsPIC development board connected to a laptop with a serial to usb converter. I'm reading the UART using Tera Term software. I know that I cannot read the UART transmission if I transmit an integer using Tera Term but maybe I can use Matlab/Simulink.
 
What I'm doing is to convert the integer to ASCII character before transmitting, but the conversion process is taking too much time to perform.
I guess that you are programming in C. You might be much quicker to convert the integer into hexadecimal and to send that.

The dsPIC will be storing numbers in 16 bit registers, so the range is 0 - 65535, but it is stored as binary 00000000000000 to 1111111111111111

If you have a number stored like that and you are changing it to decimal, there are loads of calculations to be done. To change it to hexadecimal it only needs splitting into groups of 4 bits. That should be a lot faster than it can be transmitted by the USART anyhow.
 
You need to give far more details, saying it takes 'too much time' is really pretty meaningless.
 

Yes I'm programming in C. I will try to implement your suggestion. If I'm not mistaken I can convert the 16 bit register binary to hex using the sprintf function. But I'm finding a problem to divide the 16 bit number into two sets of 8 bits to send with UART.
 
You need to give far more details, saying it takes 'too much time' is really pretty meaningless.

I have written a dsPIC program to output a PWM corresponding to a sinewave. Now I would like to get some variables from this program and transmit them using UART to PC for analysis/plotting in Matlab or an other software. I have already succeeded to convert a variable to a string and transmit this string using UART to PC and then reading it using Tera Term. But I'm limited in the frequency that I can sample this variable to send to UART, mainly because of the baud rate of UART and of the conversion process from an integer to string is a bit lengthy. This will get problematic if I need to output more variables for analysis, like 4 different variables which each need to be converted to string and transmitted. Now I was thinking to as least decrease the conversion time by eliminating the conversion, if possible, and instead send an integer directly from the dsPIC development board to the PC.
 

It's still rather vague - how fast are you wanting to send the data, and how fast are your sample times?.
 
It's still rather vague - how fast are you wanting to send the data, and how fast are your sample times?.

For now I am only sampling one variable which in my case is the value of the PWM duty cycle register (PDC) which is working at 10kHz. I am sending data to UART every 1kHz, which gives me time to convert to string and send the string of 9 characters (including \n\r\0) to UART. Now I would like to sample other variables to send them to UART for a maximum of 4 variables. But if every variable is converted to string the total time it takes to convert to characters is much longer. Therefore I was thinking of sending the variables directly to UART as integers. But I need some c-code ideas to do this please.
 
Instead of converting the string to decimal ASCII, how about converting it to HEX ASCII instead, makes it a little shorter, and MUCH faster to convert - convert to decimal in the PC if you need to.
 
Instead of converting the string to decimal ASCII, how about converting it to HEX ASCII instead, makes it a little shorter, and MUCH faster to convert - convert to decimal in the PC if you need to.

I will try to write some code to try this, thanks.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…