View previous topic :: View next topic |
Author |
Message |
ktallevi
Joined: 17 Dec 2005 Posts: 58
|
PIC16F688 soft UART RX issue |
Posted: Mon Jul 13, 2009 6:07 pm |
|
|
I have tested the following code on ISIS simulator and it works fine. But when I test it on a bread board fgetc gets triggered (with nothing attached to the serial port), and all the data is 0x00.
Why is the fgetc getting triggered with nothing attached to the GPIO pin?
When I have a device attached to the GPIO pins, the data is received without any issues.
Compiler Version: 4.084
MCU: PIC16F688
Voltage: 3.3v
8Mhz Internal Osc
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EEPROM Protection
#FUSES NOIESO //Internal External Switch Over Mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
//8MHz clock
#use delay(clock=8M)
#use rs232(baud=9600,parity=N,xmit=PIN_C0,rcv=PIN_C1,bits=8,force_sw,stream=PORT)
#define rx_buffer_size 50
int8 rx_buffer[rx_buffer_size];
int rx_buffer_index = 0;
main.c
--
setup_oscillator(OSC_8MHZ|OSC_INTRC);
do {
if(kbhit(PORT))
{
rx_buffer[rx_buffer_index] = fgetc(PORT);
rx_buffer_index++;
}
if(rx_buffer_index == number_of_expected_characters)
{
return(1);
}
} while(start - seconds < timeout);
return(0);
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 13, 2009 7:31 pm |
|
|
Quote: | #use rs232(baud=9600,parity=N,xmit=PIN_C0,rcv=PIN_C1,bits=8,force_sw,stream=PORT)
Why is the fgetc getting triggered with nothing attached to the GPIO pin? |
The idle state for the Rx pin is a high level. If you don't have a Max232
chip driving the Rx pin, then you need to add a pull-up resistor on that
pin. That will keep it in the idle state, and you won't get false characters.
There is no operating system for main() to return to. I assume you're
doing this because you're getting this error:
Quote: | Function not void and does not return a value main |
Just declare main() as returning 'void'.
You should place a continuous loop at the end of main(), so the code
doesn't execute the hidden SLEEP instruction that CCS puts there.
Example:
Code: |
void main()
{
// Your code goes here
while(1); // Don't fall off the end of main()
} |
|
|
|
ktallevi
Joined: 17 Dec 2005 Posts: 58
|
|
Posted: Mon Jul 13, 2009 8:08 pm |
|
|
The other device I am interfacing to is also 3.3v, but your right , I should put a pull-up resistor on that pin for when nothing is connected.
If I move the soft-serial port to a different set of pins which have internal pull-ups, is the internal pull-up resistor value adequate?
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 13, 2009 8:10 pm |
|
|
Quote: |
If I move the soft-serial port to a different set of pins which have internal
pull-ups, is the internal pull-up resistor value adequate? |
Yes. |
|
|
|