|
|
View previous topic :: View next topic |
Author |
Message |
harshanahnd
Joined: 22 Nov 2008 Posts: 11
|
UART data transmit problem |
Posted: Wed Dec 03, 2008 11:42 pm |
|
|
Hi,
I develop a small program to get data through USB on a 18F4550 pic and transmit that data over UART of the PIC. But when I check the data that is coming from UART it always read as 0x00. Following is the code I used.
Code: |
int8 in_data[4];
switch (in_data[1])
{
case 0:
a = (char)(in_data[3]);
printf("Temperature: 0x%X ", in_data[3]);
break;
|
The value in variable in_data[3] is the one I want to print. I am getting that value from a USB packet from my PC. I checked with putting that value to a return USB packet to my PC and it correctly gives the value I previously set. So in_data[3] has my value but when I print it, it gives 00.
What could be the problem?
Thanks in advance. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 04, 2008 1:05 am |
|
|
Comment out the USB code. Load the array with some sample data.
Send it to the PC through the serial port. This will test if the RS-232
is working OK.
Or,
1. Look closely at your code to see if byte 3 is really being loaded by
the USB routine.
2. Pre-load the array with some non-zero data, such as 0x12, 0x34, 0x56, 0x78, etc., instead of filling it with zeros. Then get data from
the USB device. Then send it to the PC. If byte 3 has 0x78 in it, then
you know that your USB code is not loading the array correctly.
3. Do other tests of this type, to verify your code operation. |
|
|
Guest
|
|
Posted: Sun Dec 07, 2008 10:30 pm |
|
|
Hi,
I did all the tests. UART is working perfectly. The problem is with the USB data. When I manually set a value as you have mentioned, it got displayed correctly. Then what I did was I put the received USB packet back to the PC and interpret it in PC. Following is the code,
Code: |
out_data[0] = in_data[0];
out_data[1] = in_data[1];
out_data[2] = in_data[2];
out_data[3] = in_data[3];
usb_put_packet(1,out_data,4,USB_DTS_TOGGLE);
|
Here the value is correctly displayed on PC. (the value in in_data[3]). I cant figure out the reason why is it not getting display from UART.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 07, 2008 11:36 pm |
|
|
Did you try doing it like this ? (Add the code shown in bold)
Quote: |
out_data[0] = in_data[0];
out_data[1] = in_data[1];
out_data[2] = in_data[2];
out_data[3] = in_data[3];
for(i = 0; i < 4; i++)
{
printf("%X ", out_data[i]);
}
printf("\n\r");
usb_put_packet(1,out_data,4,USB_DTS_TOGGLE);
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|