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 support@ccsinfo.com

rs232 on PIC12F1840 not working SOLVED
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Wed Feb 26, 2020 6:32 pm     Reply with quote

Thank you for posting Ttelmah and Temtronic.

I was happy too early Sad
The PIC18F26K22 rs232 works. I made it similar as possible the the PIC12F1840
Code:
/////////////////////////////////////////////////////////////////////
//26k22rs232 test program
/////////////////////////////////////////////////////////////////////
#include <18F26K22.h>
#device ADC=10
#FUSES NOWDT,NOPBADEN,PUT,BROWNOUT,BORV29
#FUSES PLLEN,NOIESO,NOFCMEN,NOHFOFST,INTRC_IO//HSH
#FUSES MCLR,STVREN,NOLVP,NOXINST,NODEBUG
#FUSES NOPROTECT,NOCPD,NOWRT,NOWRTC,NOWRTD
#use delay(internal=32MHz)
#use rs232(baud=9600, UART1, stream=PORT1, errors)
#define LED PIN_B5
int LEDcounter=0;
int TXcounter=0;
int data=0x0A;
#int_TIMER1
void TIMER1_isr(void)
{
   LEDcounter++;
   TXcounter++;
   if(LEDcounter>=10)//500ms
   {
      LEDcounter=0;
      output_toggle(LED);
   }
   if(TXcounter>=40)
   {
      TXcounter=0;
      enable_interrupts(INT_TBE);
   }   
   set_timer1(15536);
}
#int_TBE
void TBE_isr(void)
{
   fputc(data,PORT1);
   disable_interrupts(INT_TBE);      
}      
#int_RDA
void RDA_isr(void)
{
   data=fgetc(PORT1);
   data=data+1;
   enable_interrupts(INT_TBE);
}
void main()
{
   SETUP_ADC(NO_ANALOGS);
   setup_comparator(NC_NC);   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow;
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   disable_interrupts(INT_TBE);
   enable_interrupts(GLOBAL);
   while(TRUE)
   {
      delay_us(10);
   }
}

The 12F1840 not working:
Code:
/////////////////////////////////////////////////////////////////////
//1840rs232.c rs232 test
/////////////////////////////////////////////////////////////////////
#include <12F1840.h>
#device ADC=10
#FUSES NOWDT,PUT,BROWNOUT,BORV25,NOLVP,MCLR
#FUSES INTRC_IO,PLL
#FUSES NOPROTECT,NOCPD
#use delay(internal=32MHz)
//#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,stream=PORT1,errors)
#use rs232(baud=9600, UART1, stream=PORT1, errors)
#define LED PIN_A2//flashes ones a second
int LEDcounter=0;
int TXcounter=0;
int data=0x0A;
#int_TIMER1
void TIMER1_isr(void)
{
   LEDcounter++;
   TXcounter++;
   if(LEDcounter>=10)//500ms
   {
      LEDcounter=0;
      output_toggle(LED);
   }
   if(TXcounter>=40)
   {
      TXcounter=0;
      enable_interrupts(INT_TBE);
   }   
   set_timer1(15536);
}
#int_TBE
void TBE_isr(void)
{
   fputc(data,PORT1);
   disable_interrupts(INT_TBE);      
}
#int_RDA
void RDA_isr(void)
{
   data=fgetc(PORT1);
   data=data+1;
   enable_interrupts(INT_TBE);
}   
void main()
{
   SETUP_ADC(NO_ANALOGS);
   setup_comparator(NC_NC);   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow;
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   disable_interrupts(INT_TBE);
   enable_interrupts(GLOBAL);
   while(TRUE)
   {
      delay_us(10);
   }
}

PIC1F1847 from the PIC12F1840 family don't work also:
Code:
/////////////////////////////////////////////////////////////////////
//1847rs232.c rs232 test
/////////////////////////////////////////////////////////////////////
#include <16F1847.h>
#device ADC=10
#FUSES NOWDT,PUT,BROWNOUT,BORV25,NOLVP,MCLR
#FUSES INTRC_IO,PLL
#FUSES NOPROTECT,NOCPD
#use delay(internal=32MHz)
//#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1,errors)
#use rs232(baud=9600, UART1, stream=PORT1, errors)
#define LED PIN_B5//flashes ones a second
int LEDcounter=0;
int TXcounter=0;
int data=0x0A;
#int_TIMER1
void TIMER1_isr(void)
{
   LEDcounter++;
   TXcounter++;
   if(LEDcounter>=10)//500ms
   {
      LEDcounter=0;
      output_toggle(LED);
   }
   if(TXcounter>=40)
   {
      TXcounter=0;
      enable_interrupts(INT_TBE);
   }   
   set_timer1(15536);
}
#int_TBE
void TBE_isr(void)
{
   fputc(data,PORT1);
   disable_interrupts(INT_TBE);   
}   
#int_RDA
void RDA_isr(void)
{
   data=fgetc(PORT1);
   data=data+1;
   enable_interrupts(INT_TBE);
}
void main()
{
   SETUP_ADC(NO_ANALOGS);
   setup_comparator(NC_NC_NC_NC);   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow;
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   disable_interrupts(INT_TBE);
   enable_interrupts(GLOBAL);
   while(TRUE)
   {
      delay_us(10);
   }
}

The LED works correctly on all.
I made a compare in the CCS IDE and they are similar except controllers name and fuses for PIC18F26K22.
The .LST files of the PIC12F1840 and PIC16F1847 are similar, the PIC18F26K22 completely different or I don't understand enough to judge.
Code:
//********************************************
#device PIC18F26K22
.................... #use rs232(baud=9600, UART1, stream=PORT1, errors)
*
000EE:  BTFSS  PIR1.TX1IF
000F0:  BRA    00EE
000F2:  MOVWF  TXREG1
000F4:  GOTO   00FC (RETURN)
*
00104:  BTFSS  PIR1.RC1IF
00106:  BRA    0104
00108:  MOVFF  RCSTA1,rs232_errors
0010C:  MOVFF  RCREG1,01
00110:  BTFSS  rs232_errors.1
00112:  BRA    0118
00114:  BCF    RCSTA1.CREN
00116:  BSF    RCSTA1.CREN
00118:  GOTO   011E (RETURN)
//********************************************
#device PIC16F1847
.................... #use rs232(baud=9600, UART1, stream=PORT1, errors)
*
0051:  BTFSS  PIR1.TXIF
0052:  GOTO   051
0053:  MOVLB  03
0054:  MOVWF  TXREG
*
005B:  BTFSS  PIR1.RCIF
005C:  GOTO   05B
005D:  MOVLB  03
005E:  MOVF   RCSTA,W
005F:  MOVLB  00
0060:  MOVWF  rs232_errors
0061:  MOVLB  03
0062:  MOVF   RCREG,W
0063:  MOVWF  @78
0064:  MOVLB  00
0065:  BTFSS  rs232_errors.1
0066:  GOTO   06B
0067:  MOVLB  03
0068:  BCF    RCSTA.CREN
0069:  BSF    RCSTA.CREN
006A:  MOVLB  00
//*********************************************
#device PIC12F1840
.................... #use rs232(baud=9600, UART1, stream=PORT1, errors)
*
0051:  BTFSS  PIR1.TXIF
0052:  GOTO   051
0053:  MOVLB  03
0054:  MOVWF  TXREG
*
005B:  BTFSS  PIR1.RCIF
005C:  GOTO   05B
005D:  MOVLB  03
005E:  MOVF   RCSTA,W
005F:  MOVLB  00
0060:  MOVWF  rs232_errors
0061:  MOVLB  03
0062:  MOVF   RCREG,W
0063:  MOVWF  @78
0064:  MOVLB  00
0065:  BTFSS  rs232_errors.1
0066:  GOTO   06B
0067:  MOVLB  03
0068:  BCF    RCSTA.CREN
0069:  BSF    RCSTA.CREN
006A:  MOVLB  00
//*******************************************


By the way Temtronic, I am enabling the TBE in the RX interrupt as Ttelmah wrote and when the counter getting to 2000ms. It is the same as in the PIC18F26K22 that works in both cases.
Have no idea what happening Sad

Best wishes
Joe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 26, 2020 6:54 pm     Reply with quote

Can you tell us your test procedure ?
What equipment is connected to your board ?
What software are you running (if any) to test your board ?

Give us a list of what you do to test it, so that we can do the same thing.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Wed Feb 26, 2020 8:27 pm     Reply with quote

Hi

I have a program I made 6 years ago with PIC16F1847 that the rs232 is working. Can't test it now as I need to connect keyboard and AC motor.
The .LST is like that:
Code:
.................... #use delay(internal=32M)
.................... #use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1,errors)
*
0056:  BTFSS  PIR1.TXIF
0057:  GOTO   056
0058:  MOVLB  03
0059:  MOVWF  TXREG
005A:  MOVLB  00
005B:  RETURN
*
00B6:  BTFSS  PIR1.RCIF
00B7:  GOTO   0B6
00B8:  MOVLB  03
00B9:  MOVF   RCSTA,W
00BA:  MOVLB  00
00BB:  MOVWF  rs232_errors
00BC:  MOVLB  03
00BD:  MOVF   RCREG,W
00BE:  MOVWF  @78
00BF:  MOVLB  00
00C0:  BTFSS  rs232_errors.1
00C1:  GOTO   0C5
00C2:  MOVLB  03
00C3:  BCF    RCSTA.CREN
00C4:  BSF    RCSTA.CREN
00C5:  MOVLB  00
00C6:  RETURN


What I see that in this program have two additional lines in in the TX:
Code:
005A:  MOVLB  00
005B:  RETURN

and one in the RX:
Code:
00C6:  RETURN

Maybe this gives a clue?

Best wishes
Joe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 26, 2020 8:33 pm     Reply with quote

A clue about what ? I still don't know what you are doing to test program.
Are you just looking for the LED to flash ? Are you testing the serial ? ]
What makes you think the program fails. List your criteria.

If you are testing the serial, then post what terminal program you are
using on your PC, and post what characters or other data that you are
sending to your board.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Wed Feb 26, 2020 8:56 pm     Reply with quote

Sorry PCM Programmer, I didn't see your post before posting my last post.

The only thing connected to the boards are the LED, the TTL to USB cable (FTDI) and 5 VDC power supply.
The same ICD U64 programmer for all.
I have two laptops and testing with both.
I have the YAT terminal, works OK with the PIC18F26K22 as I mentioned before. I am working with YAT long time already.
Tested also with a very old very basic terminal, I have same results.
I am testing with the posted programs from my post before your last post with all 3 programs, they compiles and blink the LED with correct timing.

The test procedure:
* Connecting the TTL to USB cable to the board.
* Opening the YAT terminal.
* Connecting the power supply while OFF.
* Turning ON the power supply.
* Reading the default byte (0x0A) sent by the board (or attempting to read in the case of the 1840 & 1847) every 2 seconds.
* Sending one byte and get back data+1 (in the case of the 26K22). Repeating the send/receive a few times.
The byte I am sending is 0x55 or 0x44 or 0x33, getting back 0x56 or 0x45 or 0x34.

Hope it helps to help me
Best wishes
Joe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 27, 2020 3:25 am     Reply with quote

gjs_rsdi wrote:

with all 3 programs, they compiles and blink the LED with correct timing.

* Reading the default byte (0x0A) sent by the board (or attempting
to read in the case of the 1840 & 1847) every 2 seconds.
* Sending one byte and get back data+1 (in the case of the 26K22).
Repeating the send/receive a few times.
The byte I am sending is 0x55 or 0x44 or 0x33, getting back 0x56 or
0x45 or 0x34.

That's how it behaves if the test works. What results do you get if it fails ?
Post what happens when it fails.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Thu Feb 27, 2020 5:27 am     Reply with quote

What I mean about fail is that I don't get any serial communication. Just the LED blinks.

Working
With the 26K22 I am getting a byte every 2 seconds as expected and data+1 after sending a byte from the terminal.

Fails
With the 12F1840 and 16F1847 not getting a byte every 2 seconds and no data+1 after sending a byte from the terminal.

Best wishes
Joe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 27, 2020 1:04 pm     Reply with quote

I installed CCS vs. 5.062 and tested it with a 16F1847. I used your test
program from here:
http://www.ccsinfo.com/forum/viewtopic.php?t=58552&start=14
It worked.

Have you checked your pinouts ?
The 18F26K22 uses pins C6, C7 for Tx, Rx.
The 16F1847 uses B2, B1 for Tx, Rx.
The 12F1840 uses A0, A1 for Tx, Rx.
When you change PICs, the serial port pins change.
temtronic



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

View user's profile Send private message

PostPosted: Thu Feb 27, 2020 1:07 pm     Reply with quote

Any chance those PICs have assignable serial pins, using the APFCON register ?? IF so, what should be defaults may not be if the 'Wizard' is involved.
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Thu Feb 27, 2020 1:16 pm     Reply with quote

You are sure you are checking the right pins?.
The default is RX on RB1, TX on RB2.
You should also turn off the SPI peripheral since this can share the pins.
The code will differ massively, understand the PIC12/16 have different
instruction capabilities than the PIC18. The compiler generates working
code, so something is wrong in what is being done.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

PostPosted: Thu Feb 27, 2020 5:10 pm     Reply with quote

Hi

I changed PIC's to new and everything working.
It seems that I damaged the PIC's during my testings Sad

Sorry for all this topic and the time spent to try to help me Embarassed
Apologizing for that Embarassed

If the moderator can delete all this topic, please delete.

Best wishes
Joe
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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