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

Need HW 232, generating SW 232

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



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

Need HW 232, generating SW 232
PostPosted: Wed Oct 19, 2011 9:54 am     Reply with quote

My interrupts and alternate pin function are not working, i believe it is because the code is generating a software 232 instead of a hardware 232, what am i missing?

I know the interrupts will not work on a software generated 232, as well as the alternate pin location of the built in EUSART.

Somebody set me straight.


Code:

//CCS PCM C Compiler, Version 4.109, 53204               19-Oct-11 11:22


#include <16LF1827.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                      //Master Clear pin enable
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES WDT_NOSL             
#FUSES NOCLKOUT             
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOVCAP               
#FUSES PLL                   
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BORV19               
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=2MHz)
#use rs232(UART1, baud=9600, PARITY=N, BITS=8, STOP=1)

#int_RDA
void  RDA_isr(void)
{
char c;
c = getc();
putc(c);  // Echo back all incoming characters
}

void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_2MHZ|OSC_NORMAL|OSC_PLL_OFF,0);

    //Transmit M
    while(true){
       fputc('M');
      delay_ms(1000);
    }

}



Last edited by mtsoule on Wed Oct 19, 2011 11:18 am; edited 2 times in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 10:54 am     Reply with quote

1) Always post your compiler version!

2)
Code:
setup_spi2(SPI_SS_DISABLED);
This is an old bug in the CCS Code Wizard, probably not related to your problem but an incorrect configuration anyway. Should be changed to:
Code:
setup_spi2(FALSE);


3) What speed do you want the PIC to run? You have the PLL fuse set, a #delay of 4MHz and a setup_oscillator for 2MHz without PLL. Keep things simple and consistent and there is a larger chance of things working as expected.
Verify your actual clock speed by having a LED blink at 1 second interval and meassure with a stopwatch by counting the flashes for a period of at least 10 seconds.

4)
Code:
// Put the UART on pins A4, A5 for Tx, Rx.
void select_alt_pins0(void)
{
#byte APFCON0 = getenv("SFR:APFCON0")

APFCON0 |= 0x84;  // Select alternate pins for Tx, Rx

}
This makes no sense to me. According to the datasheet the Tx pin can be changed from from RB1 to RB2 using APFCON0.7 and Rx from RB2 to RB5 using APFCON1.0 You want to change the wrong pins and the 0x04 in 0x84 is not required.

5) Keep example programs as short as possible for the best responses. Your program is way too big for me to start wasting my time by examining the assembly file. Remove all unnecessary initialization code and all interrupt related stuff. Post a program of maximum 10 lines, 20 including fuses.
mtsoule



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 11:14 am     Reply with quote

My compiler version is at the top of the list file
Code:

CCS PCM C Compiler, Version 4.109              19-Oct-11 11:22


Thanks for pointing out the bug for SPI2, i will make the change.

I want to run at 2MHz, I noticed PLL Fuse, after the post, I do have everything set to 2MHz.

Still do not understand why it generates software 232, when I would expect it to use the hardware UART. I believe I have everything in place for that.

Also, ignore the pin change in the comments, i am NOT using A4 and A5 for Tx an Rx

I apologize for the long code, i will repost shorter code.

Code:

#include <16LF1827.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                      //Master Clear pin enable
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES WDT_NOSL             
#FUSES NOCLKOUT             
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOVCAP               
#FUSES PLL                   
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BORV19               
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=2MHz)
#use rs232(UART1, baud=9600, PARITY=N, BITS=8, STOP=1)

#int_RDA
void  RDA_isr(void)
{
char c;
c = getc();
putc(c);  // Echo back all incoming characters
}

void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_2MHZ|OSC_NORMAL|OSC_PLL_OFF,0);

    //Transmit M
    while(true){
       fputc('M');
      delay_ms(1000);
    }

}

ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 11:50 am     Reply with quote

My mistake for overlooking the compiler version number.

Code:
#FUSES PLL

If you don't want to use PLL it is best to remove this line. Probably the setup_oscillator function overrules the fuse, but why take chances?

I don't have v4.109. Can you post the assembly listing?
mtsoule



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 11:54 am     Reply with quote

Assembly listing:
Code:

CCS PCM C Compiler, Version 4.109               19-Oct-11 13:52

               Filename: D:\Designs\CVM_3\CCS\main.lst

               ROM used: 172 words (4%)
                         Largest free fragment is 2048
               RAM used: 10 (3%) at main() level
                         24 (6%) worst case
               Stack:    3 worst case (1 in main + 2 for interrupts)

*
0000:  MOVLP  00
0001:  GOTO   081
0002:  NOP
*
0004:  CLRF   03
0005:  CLRF   0A
0006:  MOVLB  00
0007:  MOVF   77,W
0008:  MOVWF  20
0009:  MOVF   78,W
000A:  MOVWF  21
000B:  MOVF   79,W
000C:  MOVWF  22
000D:  MOVF   7A,W
000E:  MOVWF  23
000F:  CLRF   05
0010:  MOVLW  91
0011:  MOVWF  04
0012:  BTFSS  00.5
0013:  GOTO   016
0014:  BTFSC  11.5
0015:  GOTO   01F
0016:  MOVF   20,W
0017:  MOVWF  77
0018:  MOVF   21,W
0019:  MOVWF  78
001A:  MOVF   22,W
001B:  MOVWF  79
001C:  MOVF   23,W
001D:  MOVWF  7A
001E:  RETFIE
001F:  MOVLP  00
0020:  GOTO   046
.................... 
.................... #include <16LF1827.h> 
.................... //////// Standard Header file for the PIC16LF1827 device ////////////////
.................... #device PIC16LF1827
.................... #list
.................... 
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer 
.................... #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT 
.................... #FUSES PUT                      //Power Up Timer 
.................... #FUSES NOPROTECT                //Code not protected from reading 
.................... #FUSES MCLR                      //Master Clear pin enable 
.................... #FUSES NOCPD                    //No EE protection 
.................... #FUSES NOBROWNOUT               //No brownout reset 
.................... #FUSES NOIESO                   //Internal External Switch Over mode disabled 
.................... #FUSES NOFCMEN                  //Fail-safe clock monitor disabled 
.................... #FUSES WDT_NOSL               
.................... #FUSES NOCLKOUT               
.................... #FUSES NOWRT                    //Program memory not write protected 
.................... #FUSES NOVCAP                 
.................... #FUSES PLL                     
.................... #FUSES STVREN                   //Stack full/underflow will cause reset 
.................... #FUSES BORV19                 
.................... #FUSES NODEBUG                  //No Debug mode for ICD 
.................... #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O 
.................... 
.................... #use delay(internal=2MHz) 
*
0071:  MOVLW  20
0072:  MOVWF  05
0073:  MOVLW  06
0074:  MOVWF  04
0075:  MOVF   00,W
0076:  BTFSC  03.2
0077:  GOTO   07F
0078:  MOVLW  A5
0079:  MOVWF  77
007A:  DECFSZ 77,F
007B:  GOTO   07A
007C:  NOP
007D:  DECFSZ 00,F
007E:  GOTO   078
007F:  MOVLP  00
0080:  GOTO   0A9 (RETURN)
.................... #use rs232(UART1, baud=9600, PARITY=N, BITS=8, STOP=1) 
*
0021:  MOVLB  01
0022:  BCF    0D.1
0023:  MOVLB  02
0024:  BCF    0D.1
0025:  MOVLW  08
0026:  MOVWF  78
0027:  GOTO   028
0028:  NOP
0029:  BSF    78.7
002A:  GOTO   03B
002B:  BCF    78.7
002C:  MOVLB  00
002D:  RRF    28,F
002E:  MOVLB  02
002F:  BTFSC  03.0
0030:  BSF    0D.1
0031:  BTFSS  03.0
0032:  BCF    0D.1
0033:  BSF    78.6
0034:  GOTO   03B
0035:  BCF    78.6
0036:  DECFSZ 78,F
0037:  GOTO   02C
0038:  GOTO   039
0039:  NOP
003A:  BSF    0D.1
003B:  MOVLW  0A
003C:  MOVWF  04
003D:  DECFSZ 04,F
003E:  GOTO   03D
003F:  GOTO   040
0040:  BTFSC  78.7
0041:  GOTO   02B
0042:  BTFSC  78.6
0043:  GOTO   035
0044:  MOVLB  00
0045:  RETURN
0046:  MOVLB  01
0047:  BSF    0D.1
0048:  MOVLB  00
0049:  BTFSC  0D.1
004A:  GOTO   049
004B:  MOVLW  08
004C:  MOVWF  77
004D:  CLRF   28
004E:  BSF    77.7
004F:  GOTO   05E
0050:  BCF    77.7
0051:  GOTO   05E
0052:  BCF    03.0
0053:  BTFSC  0D.1
0054:  BSF    03.0
0055:  RRF    28,F
0056:  BSF    77.6
0057:  GOTO   05E
0058:  BCF    77.6
0059:  DECFSZ 77,F
005A:  GOTO   052
005B:  MOVF   28,W
005C:  MOVWF  78
005D:  GOTO   069
005E:  MOVLW  0B
005F:  BTFSC  77.7
0060:  MOVLW  03
0061:  MOVWF  78
0062:  DECFSZ 78,F
0063:  GOTO   062
0064:  BTFSC  77.7
0065:  GOTO   050
0066:  BTFSC  77.6
0067:  GOTO   058
0068:  GOTO   052
.................... 
.................... #int_RDA 
.................... void  RDA_isr(void) 
.................... { 
.................... char c; 
.................... c = getc(); 
0069:  MOVF   78,W
006A:  MOVWF  27
.................... putc(c);  // Echo back all incoming characters 
006B:  MOVF   27,W
006C:  MOVWF  28
006D:  CALL   021
.................... } 
.................... 
006E:  BCF    11.5
006F:  MOVLP  00
0070:  GOTO   016
.................... void main() 
.................... { 
*
0081:  CLRF   05
0082:  CLRF   04
0083:  MOVLW  1F
0084:  ANDWF  03,F
0085:  MOVLW  64
0086:  MOVLB  01
0087:  MOVWF  19
0088:  BCF    0D.1
0089:  MOVLB  02
008A:  BSF    0D.1
008B:  MOVLB  03
008C:  CLRF   0C
008D:  CLRF   0D
008E:  MOVLB  02
008F:  CLRF   11
0090:  CLRF   12
0091:  CLRF   13
0092:  CLRF   14
....................    enable_interrupts(INT_RDA); 
0093:  MOVLB  01
0094:  BSF    11.5
....................    enable_interrupts(GLOBAL); 
0095:  MOVLW  C0
0096:  IORWF  0B,F
....................    setup_oscillator(OSC_2MHZ|OSC_NORMAL|OSC_PLL_OFF,0); 
0097:  MOVLW  60
0098:  MOVWF  19
0099:  CLRF   18
009A:  MOVLB  00
009B:  CLRF   24
009C:  BTFSC  0B.7
009D:  BSF    24.7
009E:  BCF    0B.7
.................... 
....................     //Transmit M 
....................     while(true){ 
....................        fputc('M'); 
009F:  MOVLW  4D
00A0:  MOVWF  28
00A1:  CALL   021
00A2:  BTFSC  24.7
00A3:  BSF    0B.7
....................       delay_ms(1000); 
00A4:  MOVLW  04
00A5:  MOVWF  25
00A6:  MOVLW  FA
00A7:  MOVWF  26
00A8:  GOTO   071
00A9:  DECFSZ 25,F
00AA:  GOTO   0A6
....................     } 
00AB:  GOTO   09B
.................... 
.................... } 
.................... 
.................... 
00AC:  SLEEP

Configuration Fuses:
   Word  1: 09D4   PUT NOPROTECT MCLR NOCPD NOBROWNOUT NOIESO NOFCMEN WDT_NOSL INTRC_IO NOCLKOUT
   Word  2: 1613   NOWRT NOVCAP PLL_SW STVREN BORV19 NODEBUG NOLVP
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 1:21 pm     Reply with quote

Looks like a bug in the CCS Device Database. The interrupt handler is generated but is using bit-banging for sending and receiving the data. A combination normally not possible.

The PIC16F1827 was very new in compiler v4.109 but current version is v4.125. Very likely the bug has been fixed but someone else with a newer version has to confirm this.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 2:12 pm     Reply with quote

Compiler vs. 4.125 does use the hardware UART for the 16FL1827:
See the comments below which show it's using the correct registers:
Code:

..... #use rs232(UART1, baud=9600, PARITY=N, BITS=8, STOP=1) 
*
0021:  BTFSS  11.4  // PIR1.TXIF
0022:  GOTO   021
0023:  MOVLB  03
0024:  MOVWF  1A  // TXREG
0025:  MOVLB  00
0026:  RETURN

................... #int_RDA 
.................... void  RDA_isr(void) 
.................... { 
.................... char c; 
.................... c = getc(); 
0027:  BTFSS  11.5   // PIR1.RCIF
0028:  GOTO   027
0029:  MOVLB  03
002A:  MOVF   19,W  // RCREG
002B:  MOVLB  00
002C:  MOVWF  27
.................... putc(c);   
002D:  MOVF   27,W
002E:  CALL   021
.................... }
.................... } 
.................... 
002F:  BCF    11.5  // PIR1.RCIF
0030:  MOVLP  00
0031:  GOTO   016

.................... void main() 
.................... { 
*
0042:  CLRF   05
0043:  CLRF   04
0044:  MOVLW  1F
0045:  ANDWF  03,F

0046:  MOVLW  62
0047:  MOVLB  01
0048:  MOVWF  19  // OSCCON

0049:  MOVLW  0C
004A:  MOVLB  03
004B:  MOVWF  1B  // SPBRGL

004C:  MOVLW  A6
004D:  MOVWF  1E  // TXSTA

004E:  MOVLW  90
004F:  MOVWF  1D  // RCSTA

0050:  CLRF   0C
0051:  CLRF   0D
0052:  MOVLB  02
0053:  CLRF   12
0054:  CLRF   11
0055:  CLRF   14
0056:  CLRF   13
....................    enable_interrupts(INT_RDA); 
0057:  MOVLB  01
0058:  BSF    11.5  // PIR1.RCIF
....................    enable_interrupts(GLOBAL); 
0059:  MOVLW  C0
 
mtsoule



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 2:29 pm     Reply with quote

Thank you ckielstra and PCM programmer, i have purchased the maintenance update, i will post my results upon arrivial.
mtsoule



Joined: 19 Oct 2011
Posts: 31

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 2:44 pm     Reply with quote

I have received the update, and just as you said, it did fix the problem. Lesson learned STAY UP-TO-DATE!!
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