Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

dsPIC30f2010 UART communication

Status
Not open for further replies.

Jean-Pierre du Plessis

Newbie level 6
Joined
Dec 6, 2010
Messages
11
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,398
If someone can pease help me. I have trouble sending intigers to my serial port from my dsPIC. I have setup the UART on the pic using the c liabraries. The pic is able to send strings of carracters and it is recevied in hyperterminal.
I use the function:
Code:
 putsUATR1((unsigned int *)Txdata)

This sends the array of char to the UART.
And if I use printf it does the same, but only if I type a string like this:
Code:
printf("Helo World");
or like this:
Code:
printf("%c",35);
This sends a # and only 38% of my memory is used on my pic.

Then when I try sending the following:
Code:
prinf("%c %c",35,13);
or anything simular or an integer with %d, my pics memory doubles and when I program my device it programs but the target is halted instantly.

I want to send intiger values to matlab, some of my varuables used in the program for logging. Please if any one have any idea how to doe this to get it to work.
 

Have you considered using the sprintf() routine to build a string which can then be passed to the putsUATR1()?

By the way, I assume the last code snippet is a typo, the 't' is missing in printf().


BigDog
 

I just tried sprintf(), and the memory also just double on the device and the device is halted. What I did so far is the following, to create a string of the variables separated by an space.
Code:
   itoa(buffer,ADCxvalue,10);                                                   //Copy a integer value into a string buffer
   strcat(buffer," " );                                                         //Combine strings
   itoa(str,errorX,10);                                                         //Copy a integer value into a string buffer
   strcat(buffer,str);                                                          //Combine strings
   strcat(buffer," ");                                                          //Combine strings
   itoa (str,i,10);
   strcat(buffer,str);
   strcat(buffer," ");

This works for transmitting the string, but now I have problems with MATLAB. In matlab I make the serial buffer the same size as the resulting string or one more, or even a few more. But matlab reads the data but not as a string at a time. It fills the buffer of what values are sent at the moment. For example.

I send: "abc 567 K"
Then in matlab I run a loop of 10 readings of the serial port. Then I receive something in the line of the following.

1: " 567 k abc"
2: "67 K abc 5"
3: " K abc 567"

And so forth. Matlab also gives the following error.

Warning: The input buffer was filled before the Terminator was
reached.

I am searching Google to find the answer, I have even enter the end of string character manually. Adding the following line.
Code:
strcat(buffer,"\0");

I am desperately trying to get useful values in matlab, as well it miss a lot of values. The dspic sends continuously but matlab only records every other value.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top