|
|
View previous topic :: View next topic |
Author |
Message |
Vefa Guest
|
Serial comm baud 57600 |
Posted: Mon Feb 05, 2007 5:15 pm |
|
|
Hi Everyone,
I am trying to communicate (serial) with an IMU. When I connect the IMU to hyperterminal I can see the menu and activate and use it. However when I use an 18F8722 pic to communicate with it I read a nonsense string.
IMU's baud rate is set to 57600. The crystal is 10MHz. I can't change the baud rate of the IMU. Below is my code.
Does anyone have an idea why I can't read the correct data?
Thanks,
#include <18F8722>
#include <24515.c>
#include <stdlib.h>
#include <math.h>
#define LED PIN_F0
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=57600, xmit=PIN_G1, rcv=PIN_G2, stream=imu, DISABLE_INTS)
#use rs232(baud=57600, xmit=PIN_A4, rcv=PIN_A5, stream=PC, DISABLE_INTS)
main()
{
while(1)
{
c = fgetc(imu);
fputc(c,PC);
}
} // end of main |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 05, 2007 5:57 pm |
|
|
You're using a soft UART for the PC stream. Your Tx pin is on pin A4,
which is an open-drain output. Do you have a pull-up resistor on that
pin ? You need one. Something between 1K and 4.7K will work.
Also, when you post code, select the tickbox to Disable HTML.
Notice how two of your #include files are missing ? That's because
HTML is enabled. Also, it's best to put the code in a Code block,
to preserve the formatting. |
|
|
Vefa Guest
|
|
Posted: Tue Feb 06, 2007 3:34 pm |
|
|
Even though I am still having problem, your information was very useful. I swithced to D1 and D2 instead of using A4 and A5. Thank you very much. |
|
|
Vefa Guest
|
Hardware interrupt |
Posted: Wed Feb 07, 2007 9:08 am |
|
|
Ok. Now I can read meaningful data. However this time I am missing some data. In order not to miss data I tried hardware interrupt. Somehow I can't get it working. Does anyone have an idea why it does not work with hardware interrupt?
The code that works:
Code: |
#include <18F8722.H>
#include <24515.c>
#include <stdlib.h>
#include <math.h>
#define LED PIN_F0
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=57600, xmit=PIN_G1, rcv=PIN_G2, stream=imu, DISABLE_INTS)
#use rs232(baud=57600, xmit=PIN_D1, rcv=PIN_D2, stream=PC, DISABLE_INTS)
main()
{
char c;
while(1)
{
c = fgetc(imu);
fputc(c, PC);
}
} // end of main
|
The code that does not work:
Code: |
#include <18F8722.H>
#include <24515.c>
#include <stdlib.h>
#include <math.h>
#define LED PIN_F0
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=57600, xmit=PIN_G1, rcv=PIN_G2, stream=imu, DISABLE_INTS)
#use rs232(baud=57600, xmit=PIN_D1, rcv=PIN_D2, stream=PC, DISABLE_INTS)
#INT_RDA2 // RS232 interrupt
void dataRda_isr(void)
{
char c;
c = fgetc(imu);
fputc(c,PC);
}
void main()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA2);
while(1)
{
output_high(LED);
delay_ms(200);
output_low(LED);
delay_ms(200);
}
} // end of main
|
I tried also the following:
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
Thanks bunch
Vefa |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 07, 2007 12:44 pm |
|
|
Post your compiler version. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Feb 07, 2007 1:02 pm |
|
|
Why do you continue to use a software UART when you have a chip with 2 hardware UARTS? Hardware UARTS will give a lot less problems than the software based UARTS, especially for the higher baudrates like 57600 you are using.
My suggestion is that you move the software UART on pins D1 and D2 to the hardware UART on C6 and C7. |
|
|
Guest
|
was away |
Posted: Sat Feb 10, 2007 12:41 pm |
|
|
My compiler version is 4.
I tried using C6 & C7 instead of D1 & D2 without doing any hardware interrupt. The code that worked with D1 & D2 now outputs some weird characters. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Feb 10, 2007 5:49 pm |
|
|
Strange that you have these errors when using two hardware UARTS.
Try the program below and tell us if you still receive garbage. Note that I removed the DISABLE_INTS keyword as it has little use for hardware UARTS. I also added the ERRORS directive which will clear a possible hardware stall on receive buffer overflow.
Code: | #include <18F8722.H>
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=57600, xmit=PIN_G1, rcv=PIN_G2, stream=imu, ERRORS)
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7, stream=PC, ERRORS)
main()
{
char c;
while(1)
{
c = fgetc(imu);
fputc(c, PC);
}
} |
Which terminal program are you using? Hyperterm has caused me a lot of headaches. |
|
|
Vefa Guest
|
|
Posted: Mon Feb 12, 2007 4:59 pm |
|
|
ckielstra, I tried your code. I also connected a pull up resistor to A4. Both give the following output:
Quote: |
•›í¿•›í¿•›—Këå}í¿•Ÿege{«Këå}í¿•›í¿•›í¿•Këå}í¿•Ÿí¿•í¿••Këå}í¿•›í¿•
›í¿•››Këå}í¿•Ÿí¿••í¿•Këå}í¿•›í¿•™í¿•Këå}í¿•Ÿí¿•«Këå}í¿•›í¿•™í¿•
Këå}í¿•Ÿí¿••í¿•Këå}í¿•›í¿•™í¿•›—Këå}í¿•Ÿí¿••í¿•c©½^µ¿•›í¿•›í¿•›Këå}í¿
•Ÿí¿••í¿•Këå}í¿•›í¿•™í¿•›—Këå}í¿•Ÿí¿••í¿•Ky_{«›í¿•™í¿•Këå}í¿•Ÿí¿•
í¿•Këå}í¿•›í¿•™í¿•›™Këå}í¿•Ÿí¿••í¿•Këå}«›í¿•›í¿•›—Këå}í¿•í¿••í¿•
Këå}í¿•›í¿•›í¿•›Këå}í¿•Ÿí¿••í¿•Këå}í¿•³ï«™í¿•›—Këå}í¿•Ÿí¿••í¿•Këå}í
¿•™í¿••í¿•›—Këå}í¿•Ÿí¿•í¿•Këå}í¿•›egf{«›“Këå}í¿•Ÿí¿•í¿•Këå}í¿•™í¿•
™í¿•›™Këå}í¿•Ÿí¿•í¿•Këå}í¿•›í¿•™í¿•›™Këå}í¿•Ÿí¿••í¿•Këå}í¿•›í¿•›«›
Këå}í¿•Ÿí¿•í¿•Këå}í¿•›í¿•›í¿•›™Këå}í¿•Ÿí¿•›í¿•Këå}í¿•›í¿•™í¿•Ùj¯}í
¿•Ÿí¿••í¿••Këå}í¿•›í¿•›í¿•›Këå}í¿•Ÿí¿•™í¿•Këå}í¿•›í¿•™í¿•›Ky
|
I am using a MAX235CPG
.
When I connect the IMU to a MAX233 directly and connect max233 to my serial port this is what I get:
Quote: |
A 510 515 519Z
A 512 513 519Z
A 510 513 515Z
A 512 512 519Z
A 510 519 519Z
A 512 515 521Z
A 510 515 519Z
A 512 513 521Z
A 510 515 519Z
A 512 512 522Z
A 510 515 519Z
A 512 512 523Z
|
The funny thing is that when I connect the serial pins in reverse order, this is what I get
Quote: |
A 512 513 524Z
A 510 MLMB*19Z
A 512 512 519Z
A 510 519 519Z
A 512 513 523Z
A 510 51B*19Z
A 512 521Z
A 508 515 519Z
A 512 513 524Z
A 510 519 519Z
B*12 512 519Z
|
I got the same result before when I was messing with a software UART and using "invert". So I guess, i need to invert the imu output or something.
Any comments?
How can I invert a hardware UART?
Thanks a lot |
|
|
Vefa Guest
|
|
Posted: Mon Feb 12, 2007 5:08 pm |
|
|
I was referring to the PC's serial pins for the last output. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Feb 12, 2007 5:35 pm |
|
|
What is the (output) voltage of the IMU? 3.3V or 5V?
What voltage is your PIC running at?
Inverting the output of a hardware UART can only be done by adding an external hardware inverter. This shouldn't be nescessary. |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 13, 2007 4:06 am |
|
|
Are you sure the 'IMU', uses RS232?...
I have a strong suspicion, that it uses RS485 instead. This would explain the inverted data when the pins were swapped. A normal RS232 device should give _nothing_ in this condition. RS485, is the more common industrial bus.
RS485, is a differential 'pair', whch needs the following things to work:
1) Connection 'A', goes to connection 'A' on each device.
2) Connection 'B' goes to connection 'B' on each device. Reversing these will result in garbaged start bits, and semi 'inverted' data, which is what you are seeing...
3) Signal termination at each end of the wire pair (normally nominally 100R, depending on the impedance of the cable).
4) Signal _bias_ applied to the bus. Some driver chips do this automatically, but if this is not done, garbage will be received, when the bus is allowed to float between transmissions.
Best Wishes |
|
|
Vefa Guest
|
|
Posted: Tue Feb 13, 2007 9:32 am |
|
|
It is RS232.
I just used an oscilloscope to compare the TX and RX signal levels of the MAX233 and PIC+MAX235 circuits. When I use MAX233 alone the RX pin is a +/-10V pwm and TX pin is a -10V DC. When I use the circuit with the PIC and MAXIM235 RX is -6/+7V pwm, and TX is around -10V. |
|
|
Vefa Guest
|
|
Posted: Tue Feb 13, 2007 10:44 am |
|
|
Both PIC and IMU is 5V. |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 13, 2007 10:55 am |
|
|
What is the part number of the IMU?.
How is the ground connected?.
The fact that data is seen, when the RX and RX pins are swapped, says that something has to be wrong with the wiring somewhere....
Best Wishes |
|
|
|
|
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
|