CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F688 soft UART RX issue

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ktallevi



Joined: 17 Dec 2005
Posts: 58

View user's profile Send private message

PIC16F688 soft UART RX issue
PostPosted: Mon Jul 13, 2009 6:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 13, 2009 7:31 pm     Reply with quote

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.


Quote:
main.c

return(0);

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

View user's profile Send private message

PostPosted: Mon Jul 13, 2009 8:08 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 13, 2009 8:10 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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