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

Simple question using UART

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



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

Simple question using UART
PostPosted: Tue Oct 19, 2021 8:23 pm     Reply with quote

I plan to use UART and SPI communication with the 18F2550.
The SPI communication is using the PIC hardware, so I have to use software for the UART, but only the hardware communication is working.
Where did I go wrong?

Code:
#include<18F2550.H>

#device PASS_STRINGS = IN_RAM
#include <string.h>

#fuses NOWDT                    //No Watch Dog Timer
//#fuses INTRC                    //Internal RC Osc
#fuses HS
#fuses NOPUT                    //No Power Up Timer
#fuses NOPROTECT                //Code not protected from reading
#fuses NOBROWNOUT               //No brownout 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 NOCPD                    //No EE protection

#use delay(clock=4000000)
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1) //OK
#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=PORT1)//:(
//-------------------------------------------------------------
void main()
{
 char Rs_buf[17];
 setup_comparator(NC_NC_NC_NC);

 while(true)
  {
   Rs_buf[0] = fgetc(PORT1);
   if(Rs_buf[0]=='w'){fputc('k',PORT1);}
  }
}
//.........
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Tue Oct 19, 2021 10:46 pm     Reply with quote

Honestly, use the UART.
SPI doesn't mind being done in software. Because it is a synchronous
interface, if there are delays in the transmission, these don't matter.
The UART is an asynchronous interface and needs to be sent and
received without breaks,
Honestly thou the 4550, is a very old chip. Many of the more modern
PIC's allow the UART and SPI to be moved (with PPS), and often have
multiple UART's and SPI interfaces.

However, the reason it is not working is that the chip is not clocked
correctly. HS says you have a crystal >4MHz. Yet you are specifying
4MHz. Then you are not specifying the CPUDIV fuse. The default for
this is not /1, Your chip I'd suspect is running at 2MHz from the 4MHz
crystal. Result comms don't work,
However I'd have expected that to give problems with the hardware comms
as well. Are you sure this is running at the right rate?.
Other thing though is that be default portB (depending on compiler
version), will default to starting setup as analog. You need the fuse
NOPBADEN to use this port for digital I/O.
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

PostPosted: Wed Oct 20, 2021 9:30 am     Reply with quote

Quote:
Honestly, use the UART.
SPI doesn't mind being done in software. Because it is a synchronous
interface, if there are delays in the transmission, these don't matter.

Thanks for the idea.
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Wed Oct 20, 2021 11:15 pm     Reply with quote

Have you tried the NOPBADEN fuse?.
This will probably get your test working.
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