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

#USE RS232 Hard/Soft mode?

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

#USE RS232 Hard/Soft mode?
PostPosted: Tue Feb 04, 2014 11:56 am     Reply with quote

Hello! I have to use serial communication rs232. The question is: If I assign XMIT and RCV to different of datasheet pointed as hardware pins, is it still hardware rs232? In other words, if I am not using the hardware uart transfer pins, am I using hardware communication yet? Actually, what determines in which mode(hardware/software) am I?
_________________
A person who never made a mistake never tried anything new.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 11:58 am     Reply with quote

if you change pins... you are using software.
_________________
CCS PCM 5.078 & CCS PCH 5.093
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 12:09 pm     Reply with quote

Gabriel wrote:
if you change pins... you are using software.


Unless you're using a PPS capable PIC and can move signal pins around.

(one example is the PIC18FxxJ11's)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 1:05 pm     Reply with quote

The problem is that the PIC I am using 18F4550 RX and SDO match. So I cant use both - hardware SPI and hardware UART. Can I?

Thank you for reply!
_________________
A person who never made a mistake never tried anything new.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Feb 04, 2014 1:37 pm     Reply with quote

if you can use hardware RX handshaking reception hold-off , then a bit of creative external 74HC logic 'glue' can perhaps enable what you seek to do ,

really it it depends on the necessity of neither the rs-232 RX nor the SDO/SDI features being uncontrolled asynchronous in nature.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 2:24 pm     Reply with quote

Quote:

The problem is that the PIC I am using 18F4550 RX and SDO match. So I cant use both - hardware SPI and hardware UART. Can I?

I assume that the internal build-in logical hardware structure of any MCU is clever enough to disable the Rx (INPUT) hardware UART while toggling SDO (OUTPUT)
Each module that share a common PIN has this exclusive behaviour.

Humberto
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 2:29 pm     Reply with quote

I think I can handle with software UART and hardware SPI. Thank you all for valuable information!
_________________
A person who never made a mistake never tried anything new.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 2:34 pm     Reply with quote

Each module that share a common PIN has this exclusive behaviour. If your external hardware meets the electrical needs to run without disturbing
mutually, I do not see any confict using the same pin for differents functions and using both modules, asychronous EUSART & SPI Module in differents
time slot, of course.

Humberto
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 3:13 pm     Reply with quote

After attempt, I will post feedback!
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 2:30 am     Reply with quote

Comments:

The things that are hard to do in software, are:
1) RS232 receive.
2) SPI slave.

Now it you only want RS232 transmission, you can either use software, or enable the UART, and turn off the receive half.
If you are the SPI master, then software SPI on other pins is easy.

The problem really appears when you want both full duplex RS232, and SPI slave operation, or you require absolute maximum speed from the SPI.

In this case I have to say 'look at another chip'. The PIC18F45K50, is pin/voltage compatible with your chip, but has SDO relocatable via fuses. It also has far fewer errata than the 4550, which makes coding a lot easier....

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 6:10 am     Reply with quote

another choice....
I upgraded from the 18f4550 to the 18f46k22 to get 2 hardware UARTS AND 2 MSSP( SPI / I2C) ports.Has more memory too !

I consider it to be the 'Swiss Army Knife' of PICs.Lots of features that you my not use in one project but will in another.By using just this PIC, you save time(and $) on cutting/testing code as you can 'cut and past' from past working projects.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 7:57 am     Reply with quote

I must admit, I assumed that since the poster was using a USB capable chip, he needed USB. This is the one 'missing thing', on the 46K22....

However (for myself), I've been tending to use the 26J50, which has the similar 'jack of all trades' ability to the 46K22, but includes USB. However this is 3.3v...

The number of serious errata on the 4550, has put me off this chip.

Both the 46K22, and 26J50, only have a couple, likely to hit in quite rare circumstances. The one that should be borne in mind for the K22, is the USART one. Download the little alternative UART configuration routine, posted here by PCM_Programmer, if using this chip.

Best Wishes
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 11:41 am     Reply with quote

My goal is to create a dev board like this:

PC <—usb_cdc—> pic18lf4550 <—spi—> enc28j60
.................................l
.................................|rs232
.........................wiz107sr

I have a success with communication but separately. I am about to find out if the complex system would work.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 12:51 pm     Reply with quote

Just use software SPI.
#use spi, allows this on any pins.

Best Wishes
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Thu Feb 06, 2014 12:50 pm     Reply with quote

I promised to post feedback. Here is the code I use as debug between PC--usb_cdc--PIC18LF4550--max232--rs232toUSB Converter--PC. I used two com ports. One for CCS USB and the other for my USB - RS232 converter. The thing that surprised me is, how come my USB works pretty well at clock frequency 48MHz despite the fact it is forbidden by 18LF4550 errata. And bidirectional data being transfered is uncorrupted. Ttelmah warned me, I should not set clock freq. above 18MHz.
Here is the code:
Code:

#include <18LF4550.h>
#fuses HSPLL, PLL4, CPUDIV1, VREGEN,  PUT, NODEBUG, CPUDIV1, USBDIV, NOXINST, NOIESO, NOWDT, NOPBADEN, NOMCLR
#use delay(clock =48M)
#use RS232(baud=9600, UART1, PARITY=N, BITS = 8, STOP=1, ERRORS)

#include <usb_cdc.h>
#DEFINE G_LED PIN_D0
#DEFINE Y_LED PIN_D1
#DEFINE R_LED PIN_C2


#INT_TIMER0
void TMR0(){
usb_task();
output_toggle(R_LED);
}

void main()
{
   int i;
   char ch_usb;
   char ch_rs;
   delay_ms(500);
   usb_init_cs();
   SETUP_TIMER_0(T0_DIV_1);
   
      while(!usb_enumerated())
      {
         usb_task();
         output_toggle(Y_LED);
         delay_ms(50);

      }
   output_low(Y_LED);
   output_high(G_LED);
   ENABLE_INTERRUPTS(INT_TIMER0);
   ENABLE_INTERRUPTS(GLOBAL);
 
while (true)
   {
      if(usb_cdc_kbhit())
      {
         ch_usb=usb_cdc_getc();
         if(ch_usb=='E')output_toggle(Y_LED);
         putc(ch_usb);
      }
      if(kbhit())
      {
         ch_rs=getc();
         if(ch_rs=='R')output_toggle(Y_LED);
         usb_cdc_putc(ch_rs);
      }
      delay_ms(5);
   }
}

This code (in my opinion) ensures me, I can use the PIC as PC<->WIZ107SR converter on TTL signal base.
The SPI is not relevant by now!
_________________
A person who never made a mistake never tried anything new.
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