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

pic18f8520 ccsc compiler - working with hardware uart2

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



Joined: 12 Jun 2008
Posts: 5
Location: ISRAEL

View user's profile Send private message Send e-mail

pic18f8520 ccsc compiler - working with hardware uart2
PostPosted: Thu Jun 12, 2008 1:38 am     Reply with quote

hi,
My problem is as follws
We have a c file which have two steps. the first step is a s.w. test system. To enter the first step i have to use pin-RG1 as input insted of its usual use as xmit pin of uart2. In other hand i have to use printf in the second step program, to print during the files needed information. i have unsuccessfully tried 2 things: read RG1 and after that in code added the line "#use rs232(........)" but because it is a preprocessor build in library function the compiler arranged it "not in the way i want" . The other option i have worked with the registers TRISG (rg1-xmit bit set to "1" - as input), RCSTA2 (SPEN -disable) TXSTA2 (TXEN - disable) .
What else can i try?
Ttelmah
Guest







PostPosted: Thu Jun 12, 2008 2:30 am     Reply with quote

Put the normal #use RS232 at the top of your code.
Add a #bit define, for the SPEN bit of the UART.
Clear this before you want to read the pin. Store the TRIS setting, then just read the pin as normal. Once you have finished, write back the stored TRIS setting, set the SPEN pin, and the UART will run as normal.
I have described this in the past for people wanting to do this on UART1, and a search here, should find the details.

Best Wishes
chaimm



Joined: 12 Jun 2008
Posts: 5
Location: ISRAEL

View user's profile Send private message Send e-mail

STILL NOT WORKING WELL READING G1
PostPosted: Thu Jun 12, 2008 3:41 am     Reply with quote

THIS IS ALL THE CODE BUT PIN-G1 STILL READ AS "1" ON THIS PIN THERE IS A PULLDOWN RESISTOR 1KOHM

#byte TXSTA1 = 0xFAC
#byte TXSTA2 = 0xF6C
#byte RCSTA1 = 0xFAB
#bit SPEN1 = 0xFAB.7
#byte RCSTA2 = 0xF6B
#bit SPEN2 = 0xF6B.7
#byte TRISC = 0xF94
#bit TX1PIN = 0xF94.6
#byte TRISG = 0xF98
#bit TX2PIN = 0xF98.1

#define RJ1 PIN_J1
#define RJ7 PIN_J7

#use rs232(baud=57600, xmit=PIN_C6,rcv=PIN_C7, STREAM=UART1)
#use rs232(baud=57600, xmit=PIN_G1,rcv=PIN_G2, STREAM=UART2)


void Main() {

int i,ii;

SPEN1=0;
TX1PIN =1;
SPEN2=0;
TX2PIN =1;

ii= input(PIN_G1);
if (ii) output_high (RJ1);
else output_high (RJ7);
SPEN1=1;
TX1PIN =0;
SPEN2=1;
TX2PIN =0;
printf("\r\nTX2_RG1 %d.\r\n",ii);
Ttelmah
Guest







PostPosted: Thu Jun 12, 2008 4:53 am     Reply with quote

Learn about 'shouting'...
Also learn about the code buttons.
You are not allowing any time for the pin to go low. _Does the pin actually go low_?.
Remember that when you change the TRIS, this happens on the last cycle of the tris instruction. The read occurs on the first cycle of the next instruction. You need to allow time for the changes to occur. .
So:
Code:


#byte RCSTA1 = 0xFAB
#bit SPEN1 = RCSTA.7
#byte RCSTA2 = 0xF6B
#bit SPEN2 = RXSTA2.7
#byte TRISC = 0xF94
#bit TX1TRIS = TRISC.6
#byte TRISG = 0xF98
#bit TX2TRIS = TRISG.1

#define RJ1 PIN_J1
#define RJ7 PIN_J7

#use rs232(baud=57600, xmit=PIN_C6,rcv=PIN_C7, STREAM=UART1)
#use rs232(baud=57600, xmit=PIN_G1,rcv=PIN_G2, STREAM=UART2)


void Main() {
   int i,ii;
   int1 uart1_tris,uart2_tris;
   SPEN1=SPEN2=FALSE;
   uart1_tris = TX1TRIS;
   uart2_tris = TX2TRIS; //Different PIC's, need the tris set or cleared
   //for serial operation, this ensures you save the current pin state
   TX1TRIS=TX2TRIS=1;
   delay_us(1);
   ii= input(PIN_G1);
   if (ii) output_high (RJ1);
   else output_high (RJ7);
   TX1TRIS =uart1_tris;;
   TX2TRIS =uart2_tris;
   SPEN1=SPEN2=TRUE;
   delay_us(240); //A garbage character will have been 'started' by
   //the pin going low. You need to ensure that enough time has passed
   //for the receiver to have taken this character, before starting serial
   //transmission.
   printf("\r\nTX2_RG1 %d.\r\n",ii);

   while(true) ;
}

With the pin connected to a pull down, this does correctly read the input pin.
Remember though, that your RS232, is going to send a garbage character when you do this, since the pin drops, which the serial driver will see as a start bit...

Best Wishes
chaimm



Joined: 12 Jun 2008
Posts: 5
Location: ISRAEL

View user's profile Send private message Send e-mail

STILL RG1 READ IN high LEVEL
PostPosted: Thu Jun 12, 2008 6:18 am     Reply with quote

great Ttelmah, Thanks
i have done exactly as you advised me. still rg1 read in high level. More than that if no #USE RS232 definition and no [printf needed, i got rg1 in low level as i want, "uart disturbs me" at this point of code.
Ttelmah
Guest







PostPosted: Thu Jun 12, 2008 7:55 am     Reply with quote

Have you got fast_io enabled?.
It does work. I have used almost exactly this code before on the 8722. I suspect the compiler is being too smart. If you are in 'standard_io' mode (the default), it is probably overriding the TRIS setting, when you try to read the pin. It 'knows' the pin is defined for serial I/O, so sets the pin for this, rather than as an input...
Either read the input register directly (which overrides the compiler with regards to TRIS), or switch to fast_io mode (which I always use, if doing anything 'complex' with the pin's I/O.
Given you probably have other I/O, which changing the mode would affect, just define the input register bit, and try reading this.

Best Wishes
chaimm



Joined: 12 Jun 2008
Posts: 5
Location: ISRAEL

View user's profile Send private message Send e-mail

The problem has been resolved
PostPosted: Thu Jun 12, 2008 10:02 am     Reply with quote

Great Ttelmah
Thanks a lot!!!!!!!!
chaimm



Joined: 12 Jun 2008
Posts: 5
Location: ISRAEL

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 12, 2008 10:04 am     Reply with quote

i will arrange the code and send it to the forum
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