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

pic18F4550 RS 232 rare issue

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



Joined: 04 Sep 2013
Posts: 25

View user's profile Send private message

pic18F4550 RS 232 rare issue
PostPosted: Sun Mar 12, 2017 11:32 pm     Reply with quote

Hello everyone,
I hope someone can help me with this strange thing.

I have a pic18F4550 using a crystal 4Mhz configure for 32Mhz PLL, I am just trying to send data via rs232 TTL to other rs232 TTL.
What is weird is that I can send data with no issue however if I try to receive data nothing happened. I attaching the code.
Code:
#include <18F4550.h>
#device ADC=10

#FUSES PLL1
#FUSES XTPLL
#FUSES CPUDIV3
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOVREGEN                 //USB voltage regulator disabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=32MHz, crystal=4MHz)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

void main(){
   char dato[4];
   while(TRUE)
   {
      printf("hola mundo\r\n");
      if(kbhit(PORT1) == true){
         gets(dato);
         printf("%S\r\n", dato);
      }
      delay_ms(1000);
   }

}


What is even more unusual is that kbhit() works fine but I can not get the char.

I already check the crystal (4MHz), capacitor (33pF), connectivity between pins and the hardware.

any idea?

please help.

thanks.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 5:37 am     Reply with quote

this...
gets(dato);

says to get a string of data, so it'll stay in a loop until it receives a RETURN (13). It 'should' be looking at your 'stream' for this data but check with the CCS manual for options.

BTW using gets() without a timeout function is not recommended.
ALSO you need to add 'errors' to the uses rs232(...options...), manual explains why.
Jay
rald



Joined: 04 Sep 2013
Posts: 25

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 9:54 am     Reply with quote

hi

thanks for reply.

I add your suggestions to my code
Code:
#include <18F4550.h>
#device ADC=10

#FUSES PLL1
#FUSES XTPLL
#FUSES CPUDIV3
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOVREGEN                 //USB voltage regulator disabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=32MHz, crystal=4MHz)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors,timeout=100)

void main(){
   char dato[4];
   while(TRUE)
   {
      printf("hola mundo\r\n");
      if(kbhit(PORT1) == true){
         while(gets(dato) != ""){}
         printf("char = %s\r\n", dato);
      }
      delay_ms(1000);
   }

}


nothing changes... the RX is not working at all...

any other idea?
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 10:02 am     Reply with quote

Have a look at the ex_sisr.c example that CCS supplies. It's in the examples folder.

Also what hardware are you using to connect PIC to the other RS232 device ?

Jay
rald



Joined: 04 Sep 2013
Posts: 25

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 10:09 am     Reply with quote

I am going to check that example.

the other device is HC-05 bluetooth.

but also I testing with an arduino.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 10:17 am     Reply with quote

Just try a simple character echo program. Then you don't have to deal
with gets(), buffers, array overrun, or anything. Example:
Code:
void main()
{
int8 c;

printf("Start\n\r");

while(TRUE)
  {
   c = fgetc(PORT1);  // Wait for a char to come in

   fputc(c, PORT1);  // Then send it back
  }

}
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 10:56 am     Reply with quote

hmmm. HC-05 bluetooth device . Is it a 5 volt device ? Most peripherals these days are 3 volt units. That PIC is a 5 volt device, so if (as I suspect) the HC-05 is 3v, you must use proper logic level conversion between the two units.
The datasheet of the 'HC-05' should/will say.

Jay
rald



Joined: 04 Sep 2013
Posts: 25

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 12:11 pm     Reply with quote

dude

Your code is working... IS WORKING!!!!

But I can only received one character per line... how do I add more buffer to rx?

Thanks a lot!!!!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 13, 2017 12:15 pm     Reply with quote

ex_sisr.c
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Mar 14, 2017 2:17 am     Reply with quote

Repeat that about the HC-05....

Be aware that the Arduino, has TTL logic inputs. Vih=2.4v
The PIC serial input has a Schmitt level input. Vih=4v.

Chips that will talk fine to an Arduino, need logic level translation to talk to a PIC.....
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