View previous topic :: View next topic |
Author |
Message |
xvoltx
Joined: 25 Oct 2013 Posts: 4 Location: Mexico
|
Problem PIC16F1938 RS232 |
Posted: Fri Oct 25, 2013 6:52 pm |
|
|
Hello I'm new in this forum. I have a problem with the PIC16F1938 and its RS232 configuration. I don't receive data correctly, I think could be the FUSES, might they help me? Here is my code:
Code: |
#include <16F1938.h>
#fuses INTRC_IO, NOWDT, NOCPD, NOBROWNOUT, NOLVP, NOPROTECT, NOMCLR
#use delay(internal=16M)
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, bits=8, stop=1, errors)
int8 receive[100];
int8 index;
#INT_RDA
void getDatas(){
disable_interrupts(INT_RDA);
while(kbhit()){
receive[index] = getc();
index++;
}
enable_interrupts(INT_RDA);
}
void main(){
enable_interrupts(INT_RDA); //RS232 receive data available
enable_interrupts(GLOBAL); //Activa interrupciones globales
while(1){
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 25, 2013 7:23 pm |
|
|
Quote: | #INT_RDA
void getDatas(){
disable_interrupts(INT_RDA);
while(kbhit()){
receive[index] = getc();
index++;
}
enable_interrupts(INT_RDA);
} |
Delete all the lines in bold. They are not necessary or a mistake.
You should get only one character per interrupt. That's the correct way
to do it.
Also, add code to check if index is greater than 99. If so, reset the index
to 0. Don't let the receive[] array index go higher than 99.
Also, when you have received the required number of characters, set a
global flag variable = TRUE. Do this inside the #int_rda routine. Then
check that flag in a loop in main(). If it's = TRUE then set the flag =
FALSE (initialize it to FALSE, also), reset the index to 0, and do something
with the received data. |
|
|
xvoltx
Joined: 25 Oct 2013 Posts: 4 Location: Mexico
|
|
Posted: Fri Oct 25, 2013 7:41 pm |
|
|
Not working, the received data are apparently wrong, for example, I send 123 in X-CTU, echo show 123 but when I putc() the array the datas are "01." without quotes. I don't show all the complete code, but index is set 0. The configuration in X-CTU is Baud=9600, Flow control=None, Data Bits=8, Parity=None, Stop=1, data sheet say this PIC supports 8 or 9 bit of TX and RX, and baud rate could be detected automatically. What can be wrong? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 25, 2013 8:04 pm |
|
|
1. Post a link to webpage for your development board (if you bought it).
If you built your own board, post a link to a schematic for the board.
You can upload the schematic to a free web hosting site, such as
http://imageshack.us and then post the link here.
2. Quote: | but when I putc() the array the datas are "01. |
Post your test program that shows this.
3. Have you done an LED blinking test, to confirm that your PIC is really
running at 16 MHz ?
4. Have your run a loopback test, to show that your PIC can send and
receive data correctly to and from itself ? See the simple #int_rda
loopback test code that I have posted in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=47854
5. Post your CCS compiler version. It's a 4 digit number (only) given
at the top of the .LST file, which will be in your project directory after
a successful compilation. Examples of CCS version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo |
|
|
xvoltx
Joined: 25 Oct 2013 Posts: 4 Location: Mexico
|
|
Posted: Fri Oct 25, 2013 9:09 pm |
|
|
1.- I use proteus to simulate, here is the schematic, is simple just to "debug" because the final application is communicating with a Xbee
2.-
Code: |
.
.
.
#INT_RDA
void getDatos(){
receiveXbee[index] = getc();
putc(receiveXbee[index]);
index++;
}
void main(void){
delay_ms(5000);
for(int g=0; g<100; g++)
putc(receiveXbee[c]);
while(1){
output_high(pin_a4);
delay_ms(1000);
output_low(pin_a4);
delay_ms(1000);
}
}
|
Results
3.- The LED blinking.
4.- It's a similar code.
5.- IDE Version 4.130 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 25, 2013 9:14 pm |
|
|
I can't help with Proteus projects. I don't use it. |
|
|
xvoltx
Joined: 25 Oct 2013 Posts: 4 Location: Mexico
|
|
Posted: Fri Oct 25, 2013 9:23 pm |
|
|
Ok, thanks for the time, I guess the #fuses are correct. Good night |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Sat Oct 26, 2013 12:14 am |
|
|
Obvious comment.
You do realise that a PIC _does not_ develop 'RS232'....
It develops async TTL serial.
RS232 is a signalling standard. To generate 'RS232' with a PIC, you need a TTL-RS232 transceiver chip.
You show the PIC connected directly to a DB9.....
Best Wishes |
|
|
|