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

FIXED: Reason For Switching To SW UART/PIC18F26k22 RDA

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



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

FIXED: Reason For Switching To SW UART/PIC18F26k22 RDA
PostPosted: Tue Jan 29, 2013 3:29 am     Reply with quote

Hi,

I'm using a 26K22 PIC with compiler version 4.112.

I'm trying to force CCS to use the hardware UART as opposed to a software one but it refuses to compile with FORCE_HW.

Is there anyway I can find out the reason for this?

Cheers,

Code:
   #include <18F26K22.h>
   #fuses INTRC_IO, NOWDT, NOBROWNOUT, NOPUT, NOLVP, NOMCLR, PLLEN
   #USE delay(internal=16Mhz, clock=64Mhz)


   #use RS232 (STREAM=PC_SERIAL, baud=9600, UART1, FORCE_HW, ERRORS)

void main () {

}


Last edited by Geps on Thu Jan 31, 2013 1:24 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Jan 29, 2013 4:49 am     Reply with quote

There isn't actually a FORCE_HW command. Only FORCE_SW for #use RS232. FORCE_HW, is for I2C, which defaults to software.
UART1, forces the hardware to be used.

If I remember, round your compiler version, the compiler sometimes failed to route the internal oscillator to the PLL. I'd be explicit in the code, and make sure this is set:
Code:

#include <18F26K22.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, NOPUT, NOLVP, NOMCLR, PLLEN
#USE delay(internal=16Mhz, clock=64Mhz)


#use RS232 (STREAM=PC_SERIAL, baud=9600, UART1, ERRORS)

void main () {
   setup_oscillator(OSC_64MHZ|OSC_INTRC);
   printf("Test message\n\r");
   do {
   } while(TRUE);
}


This merrily produces 'Test message', and is using the hardware UART.

Best Wishes
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 12:21 am     Reply with quote

Thanks Ttelmah,

When I included that line however the output from the UART was generating errors in my RealTerm application....? When I comment it out it seems to be working fine.


The original reason for me querying the HW vs SW route was due to issues with my RDA interrupt. I figured that as it wasn't getting serviced was due to a SW UART but it seems even with UART in the #use it still has issues. Is there anything glaringly obvious here that's wrong?

Code:

#include <18F26K22.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, NOPUT, NOLVP, NOMCLR, PLLEN
#USE delay(internal=16Mhz, clock=64Mhz)


#use RS232 (STREAM=PC_SERIAL, baud=115200, UART1, ERRORS)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Interrupts
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#INT_RDA
void pc_comms_isr() {
   fprintf(PC_SERIAL, "B");
}


void main () {
   int8 i = 0x00;
   //setup_oscillator(OSC_64MHZ|OSC_INTRC);
   
   delay_ms(1000);
   
   fprintf(PC_SERIAL, "Started!");
   
   
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   while (TRUE) {}
}

Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 1:42 am     Reply with quote

Two obvious things.
The ISR _must_ read the received character. Otherwise it'll loop for ever.
Second thing is printing inside the ISR. This means interrupts will be disabled in the print routine outside the ISR. Doesn't matter here, but a problem waiting to happen.
Repeat the mantra. ISR's should do _only_ what the interrupt signifies/requires. INT_RDA, should _only_ read the character. As little else as possible, but it _must_ do this.

Best Wishes
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 2:03 am     Reply with quote

Thanks, but I broke the 'golden rules' as it were as I'm just trying to get into the ISR - at the moment I can't even do that!

If I compile that, run it with an FTDI TTL lead, and after it says "Started" I send by 0xFF or 0x00 byte value but it still doesn't receive the byte - at least no "B" no comes back up.

I've checked that the bytes are going to the correct pin, and I'm receiving reliably and consistently the "Started" string so I'm confident the PIC is running fine and at the correct speed.

Just wanted to make sure that there is nothing from a firmware perspective that this chip needs to receive (all three bits for enabling the interrupts as listed in the datasheet seem to be in the asm) as it's a new chip for me.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 3:08 am     Reply with quote

OK.
Do one thing.
Remark out the #nolist a couple of lines down in the chip definition file.
Recompile, and the code will include the routines for the UART. It definately is using the UART.
Now, your compiler is fairly early for the chip you are using.
Only thing you are not doing, which I do in my code using this chip, is disabling these pins for analog I/O.
The data sheet does say:
"If the TXx/CKx pin is shared with an analog
peripheral the analog I/O function must be disabled by
clearing the corresponding ANSEL bit.
If the RXx/DTx pin is shared with an analog peripheral
the analog I/O function must be disabled by clearing
the corresponding ANSEL bit."
Then:
"PORTC<7> data input; disabled when analog input
enabled"

I wonder if this is the problem.

Best Wishes
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 10:09 am     Reply with quote

Code:
CCS PCH C Compiler, Version 4.112, 93509317               30-Jan-13 15:49

               Filename: C:\------\----------------\main.lst

               ROM used: 368 bytes (1%)
                         Largest free fragment is 65164
               RAM used: 28 (1%) at main() level
                         29 (1%) worst case
               Stack:    2 worst case (1 in main + 1 for interrupts)

*
00000:  GOTO   0114
*
00008:  MOVWF  04
0000A:  MOVFF  FD8,05
0000E:  MOVFF  FE0,06
00012:  MOVLB  0
00014:  MOVFF  FE9,0C
00018:  MOVFF  FEA,07
0001C:  MOVFF  FE1,08
00020:  MOVFF  FE2,09
00024:  MOVFF  FD9,0A
00028:  MOVFF  FDA,0B
0002C:  MOVFF  FF3,12
00030:  MOVFF  FF4,13
00034:  MOVFF  FFA,14
00038:  MOVFF  FF5,15
0003C:  MOVFF  FF6,16
00040:  MOVFF  FF7,17
00044:  MOVFF  00,0E
00048:  MOVFF  01,0F
0004C:  MOVFF  02,10
00050:  MOVFF  03,11
00054:  BTFSS  F9D.5
00056:  GOTO   0060
0005A:  BTFSC  F9E.5
0005C:  GOTO   00AE
00060:  MOVFF  0E,00
00064:  MOVFF  0F,01
00068:  MOVFF  10,02
0006C:  MOVFF  11,03
00070:  MOVFF  0C,FE9
00074:  MOVFF  07,FEA
00078:  BSF    07.7
0007A:  MOVFF  08,FE1
0007E:  MOVFF  09,FE2
00082:  MOVFF  0A,FD9
00086:  MOVFF  0B,FDA
0008A:  MOVFF  12,FF3
0008E:  MOVFF  13,FF4
00092:  MOVFF  14,FFA
00096:  MOVFF  15,FF5
0009A:  MOVFF  16,FF6
0009E:  MOVFF  17,FF7
000A2:  MOVF   04,W
000A4:  MOVFF  06,FE0
000A8:  MOVFF  05,FD8
000AC:  RETFIE 0
....................     
....................     
....................     
....................    #include <18F26K22.h> 
.................... //////// Standard Header file for the PIC18F26K22 device ////////////////
.................... #device PIC18F26K22
*
000BC:  DATA 53,74
000BE:  DATA 61,72
000C0:  DATA 74,65
000C2:  DATA 64,21
000C4:  DATA 00,00
*
000F0:  TBLRD*+
000F2:  MOVF   FF5,F
000F4:  BZ    0110
000F6:  MOVFF  FF6,1B
000FA:  MOVFF  FF7,1C
000FE:  MOVF   FF5,W
00100:  BTFSS  F9E.4
00102:  BRA    0100
00104:  MOVWF  FAD
00106:  MOVFF  1B,FF6
0010A:  MOVFF  1C,FF7
0010E:  BRA    00F0
00110:  GOTO   016A (RETURN)
.................... //#nolist
.................... //////// Program memory: 32768x16  Data RAM: 512  Stack: 31
.................... //////// I/O: 25   Analog Pins: 20
.................... //////// Data EEPROM: 1024
.................... //////// C Scratch area: 00   ID Location: 200000
.................... //////// Fuses: LP,PROTECT,NOPROTECT,BROWNOUT_NOSL,NOBROWNOUT,WDT1,NOWDT
.................... //////// Fuses: BORV45,PUT,NOPUT,CPD,NOSTVREN,STVREN,NODEBUG,DEBUG,NOLVP,WRT
.................... //////// Fuses: NOWRT,WRTD,NOIESO,NOFCMEN,NOPBADEN,CCP2B3,WRTC,WRTB,EBTR
.................... //////// Fuses: NOEBTR,EBTRB,CPB,NOLPT1OSC,NOMCLR,NOXINST,NOHFOFST,NOPLLEN
.................... //////// Fuses: PRIMARY_SW,TIMER3B5,CCP2C0,BROWNOUT,WDT8,NOEBTRB,ECL,EC_IO
.................... //////// Fuses: EC,INTRC_IO,H4,HS,PLLEN,FCMEN,BROWNOUT_SW,BORV27,WDT
.................... //////// Fuses: WDT_NOSLEEP,WDT16384,WDT4096,WDT1024,WDT256,WDT64,WDT16,WDT2
.................... //////// Fuses: PBADEN,NODELAYINTOSC,CCP2B5,LVP,NOCPB,NOWRTC,NOWRTD,INTRC,RC
.................... //////// Fuses: PRIMARY,BORV20,WDT_SW,WDT8192,WDT512,WDT32,CCP2C1,TIMER3C0
.................... //////// Fuses: XINST,NOWRTB,RC_IO,IESO,WDT32768,WDT128,LPT1OSC,NOCPD,XT
.................... //////// Fuses: WDT2048,MCLR,BORV42,WDT4,ECL_IO
.................... //////// 
.................... ////////////////////////////////////////////////////////////////// I/O
.................... // Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
.................... //                         PORT_x_PULLUPS(), INPUT(),
.................... //                         OUTPUT_LOW(), OUTPUT_HIGH(),
.................... //                         OUTPUT_FLOAT(), OUTPUT_BIT()
.................... // Constants used to identify pins in the above are:
.................... 
.................... #define PIN_A0  31744
.................... #define PIN_A1  31745
.................... #define PIN_A2  31746
.................... #define PIN_A3  31747
.................... #define PIN_A4  31748
.................... #define PIN_A5  31749
.................... #define PIN_A6  31750
.................... #define PIN_A7  31751
.................... 
.................... #define PIN_B0  31752
.................... #define PIN_B1  31753
.................... #define PIN_B2  31754
.................... #define PIN_B3  31755
.................... #define PIN_B4  31756
.................... #define PIN_B5  31757
.................... #define PIN_B6  31758
.................... #define PIN_B7  31759
.................... 
.................... #define PIN_C0  31760
.................... #define PIN_C1  31761
.................... #define PIN_C2  31762
.................... #define PIN_C3  31763
.................... #define PIN_C4  31764
.................... #define PIN_C5  31765
.................... #define PIN_C6  31766
.................... #define PIN_C7  31767
.................... 
.................... #define PIN_E3  31779
.................... 
.................... ////////////////////////////////////////////////////////////////// Useful defines
.................... #define FALSE 0
.................... #define TRUE 1
.................... 
.................... #define BYTE int8
.................... #define BOOLEAN int1
.................... 
.................... #define getc getch
.................... #define fgetc getch
.................... #define getchar getch
.................... #define putc putchar
.................... #define fputc putchar
.................... #define fgets gets
.................... #define fputs puts
.................... 
.................... ////////////////////////////////////////////////////////////////// Control
.................... // Control Functions:  RESET_CPU(), SLEEP(), RESTART_CAUSE()
.................... // Constants returned from RESTART_CAUSE() are:
.................... 
.................... #define WDT_TIMEOUT       7     
.................... #define MCLR_FROM_SLEEP  11     
.................... #define MCLR_FROM_RUN    15     
.................... #define NORMAL_POWER_UP  12     
.................... #define BROWNOUT_RESTART 14     
.................... #define WDT_FROM_SLEEP   3     
.................... #define RESET_INSTRUCTION 0     
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 0
.................... // Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER_0(),
.................... //                              SET_TIMER0() or SET_RTCC(),
.................... //                              GET_TIMER0() or GET_RTCC()
.................... // Constants used for SETUP_TIMER_0() are:
.................... #define T0_INTERNAL   0
.................... #define T0_EXT_L_TO_H 32
.................... #define T0_EXT_H_TO_L 48
.................... 
.................... #define T0_DIV_1      8
.................... #define T0_DIV_2      0
.................... #define T0_DIV_4      1
.................... #define T0_DIV_8      2
.................... #define T0_DIV_16     3
.................... #define T0_DIV_32     4
.................... #define T0_DIV_64     5
.................... #define T0_DIV_128    6
.................... #define T0_DIV_256    7
.................... 
.................... #define T0_OFF        0x80   
.................... 
.................... #define T0_8_BIT      0x40   
.................... 
.................... #define RTCC_INTERNAL   0      // The following are provided for compatibility
.................... #define RTCC_EXT_L_TO_H 32     // with older compiler versions
.................... #define RTCC_EXT_H_TO_L 48
.................... #define RTCC_DIV_1      8
.................... #define RTCC_DIV_2      0
.................... #define RTCC_DIV_4      1
.................... #define RTCC_DIV_8      2
.................... #define RTCC_DIV_16     3
.................... #define RTCC_DIV_32     4
.................... #define RTCC_DIV_64     5
.................... #define RTCC_DIV_128    6
.................... #define RTCC_DIV_256    7
.................... #define RTCC_OFF        0x80   
.................... #define RTCC_8_BIT      0x40   
.................... 
.................... // Constants used for SETUP_COUNTERS() are the above
.................... // constants for the 1st param and the following for
.................... // the 2nd param:
.................... 
.................... ////////////////////////////////////////////////////////////////// WDT
.................... // Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
.................... //                            RESTART_WDT()
.................... // WDT base is 4ms
.................... //
.................... #define WDT_ON        0x100
.................... #define WDT_OFF       0
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 1
.................... // Timer 1 Functions: SETUP_TIMER_1, GET_TIMER1, SET_TIMER1
.................... // Constants used for SETUP_TIMER_1() are:
.................... //      (or (via |) together constants from each group)
.................... #define T1_DISABLED         0
.................... #define T1_INTERNAL         0x07
.................... #define T1_EXTERNAL         0x87
.................... #define T1_EXTERNAL_SYNC    0x83
.................... #define T1_FOSC             0x47
.................... 
.................... #define T1_ENABLE_SOSC      0x08
.................... 
.................... #define T1_DIV_BY_1         0
.................... #define T1_DIV_BY_2         0x10
.................... #define T1_DIV_BY_4         0x20
.................... #define T1_DIV_BY_8         0x30
.................... 
.................... #define T1_GATE           0x8000
.................... #define T1_GATE_INVERTED  0xC000
.................... #define T1_GATE_TOGGLE    0xA000
.................... #define T1_GATE_SINGLE    0x9000
.................... #define T1_GATE_TIMER2    0x8100
.................... #define T1_GATE_COMP1     0x8200
.................... #define T1_GATE_COMP2     0x8300
.................... 
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 2
.................... // Timer 2 Functions: SETUP_TIMER_2, GET_TIMER2, SET_TIMER2
.................... // Constants used for SETUP_TIMER_2() are:
.................... #define T2_DISABLED         0
.................... #define T2_DIV_BY_1         4
.................... #define T2_DIV_BY_4         5
.................... #define T2_DIV_BY_16        6
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 3
.................... // Timer 3 Functions: SETUP_TIMER_3, GET_TIMER3, SET_TIMER3
.................... // Constants used for SETUP_TIMER_3() are:
.................... //      (or (via |) together constants from each group)
.................... #define T3_DISABLED         0
.................... #define T3_INTERNAL         0x07
.................... #define T3_EXTERNAL         0x87
.................... #define T3_EXTERNAL_SYNC    0x83
.................... #define T3_FOSC             0x47
.................... 
.................... #define T3_ENABLE_SOSC      0x08
.................... 
.................... #define T3_DIV_BY_1         0
.................... #define T3_DIV_BY_2         0x10
.................... #define T3_DIV_BY_4         0x20
.................... #define T3_DIV_BY_8         0x30
.................... 
.................... #define T3_GATE           0x8000
.................... #define T3_GATE_INVERTED  0xC000
.................... #define T3_GATE_TOGGLE    0xA000
.................... #define T3_GATE_SINGLE    0x9000
.................... #define T3_GATE_TIMER4    0x8100
.................... #define T3_GATE_COMP1     0x8200
.................... #define T3_GATE_COMP2     0x8300
.................... 
.................... // OR in one of the following to use timer 3 with a CCP unit
.................... #define  T3_CCP1_TO_2  0x48
.................... #define  T3_CCP2       0x8
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 4
.................... // Timer 4 Functions: SETUP_TIMER_4, GET_TIMER4, SET_TIMER4
.................... // Constants used for SETUP_TIMER_4() are:
.................... #define T4_DISABLED         0
.................... #define T4_DIV_BY_1         4
.................... #define T4_DIV_BY_4         5
.................... #define T4_DIV_BY_16        6
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 5
.................... // Timer 5 Functions: SETUP_TIMER_5, GET_TIMER5, SET_TIMER5
.................... // Constants used for SETUP_TIMER_5() are:
.................... //      (or (via |) together constants from each group)
.................... #define T5_DISABLED         0
.................... #define T5_INTERNAL         0x07
.................... #define T5_EXTERNAL         0x87
.................... #define T5_EXTERNAL_SYNC    0x83
.................... #define T5_FOSC             0x47
.................... 
.................... #define T5_ENABLE_SOSC      0x08
.................... 
.................... #define T5_DIV_BY_1         0
.................... #define T5_DIV_BY_2         0x10
.................... #define T5_DIV_BY_4         0x20
.................... #define T5_DIV_BY_8         0x30
.................... 
.................... #define T5_GATE           0x8000
.................... #define T5_GATE_INVERTED  0xC000
.................... #define T5_GATE_TOGGLE    0xA000
.................... #define T5_GATE_SINGLE    0x9000
.................... #define T5_GATE_TIMER6    0x8100
.................... #define T5_GATE_COMP1     0x8200
.................... #define T5_GATE_COMP2     0x8300
.................... 
.................... ////////////////////////////////////////////////////////////////// Timer 6
.................... // Timer 6 Functions: SETUP_TIMER_6, GET_TIMER5, SET_TIMER5
.................... // Constants used for SETUP_TIMER_6() are:
.................... //      (or (via |) together constants from each group)
.................... #define T6_DISABLED         0
.................... #define T6_DIV_BY_1         4
.................... #define T6_DIV_BY_4         5
.................... #define T6_DIV_BY_16        6
.................... 
.................... ////////////////////////////////////////////////////////////////// CCP
.................... // CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
.................... // CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
.................... // Constants used for SETUP_CCPx() are:
.................... #define CCP_OFF                         0
.................... #define CCP_CAPTURE_FE                  4
.................... #define CCP_CAPTURE_RE                  5
.................... #define CCP_CAPTURE_DIV_4               6
.................... #define CCP_CAPTURE_DIV_16              7
.................... #define CCP_COMPARE_SET_ON_MATCH        8
.................... #define CCP_COMPARE_CLR_ON_MATCH        9
.................... #define CCP_COMPARE_INT                 0xA
.................... #define CCP_COMPARE_INT_AND_TOGGLE      0x2       
.................... #define CCP_COMPARE_RESET_TIMER         0xB
.................... #define CCP_PWM                         0xC
.................... #define CCP_PWM_PLUS_1                  0x1c
.................... #define CCP_PWM_PLUS_2                  0x2c
.................... #define CCP_PWM_PLUS_3                  0x3c
.................... //#define CCP_USE_TIMER3                0x100  OBSOLETE, SEE TIMER-3     
.................... #word   CCP_1    =                      getenv("SFR:CCPR1L")
.................... #byte   CCP_1_LOW=                      getenv("SFR:CCPR1L")
.................... #byte   CCP_1_HIGH=                     getenv("SFR:CCPR1H")
.................... // The following should be used with the ECCP unit only (or these in)
.................... #define CCP_PWM_H_H                     0x0c
.................... #define CCP_PWM_H_L                     0x0d
.................... #define CCP_PWM_L_H                     0x0e
.................... #define CCP_PWM_L_L                     0x0f
.................... 
.................... #define CCP_PWM_FULL_BRIDGE             0x40
.................... #define CCP_PWM_FULL_BRIDGE_REV         0xC0
.................... #define CCP_PWM_HALF_BRIDGE             0x80
.................... 
.................... #define CCP_SHUTDOWN_ON_COMP1           0x100000
.................... #define CCP_SHUTDOWN_ON_COMP2           0x200000
.................... #define CCP_SHUTDOWN_ON_COMP            0x300000
.................... #define CCP_SHUTDOWN_ON_INT0            0x400000
.................... #define CCP_SHUTDOWN_ON_COMP1_INT0      0x500000
.................... #define CCP_SHUTDOWN_ON_COMP2_INT0      0x600000
.................... #define CCP_SHUTDOWN_ON_COMP_INT0       0x700000
.................... 
.................... #define CCP_SHUTDOWN_AC_L               0x000000
.................... #define CCP_SHUTDOWN_AC_H               0x040000
.................... #define CCP_SHUTDOWN_AC_F               0x080000
.................... 
.................... #define CCP_SHUTDOWN_BD_L               0x000000
.................... #define CCP_SHUTDOWN_BD_H               0x010000
.................... #define CCP_SHUTDOWN_BD_F               0x020000
.................... 
.................... #define CCP_SHUTDOWN_RESTART            0x80000000
.................... 
.................... #define CCP_PULSE_STEERING_A            0x01000000
.................... #define CCP_PULSE_STEERING_B            0x02000000
.................... #define CCP_PULSE_STEERING_C            0x04000000
.................... #define CCP_PULSE_STEERING_D            0x08000000
.................... #define CCP_PULSE_STEERING_SYNC         0x10000000
.................... 
.................... #word   CCP_2    =                      getenv("SFR:CCPR2L")
.................... #byte   CCP_2_LOW=                      getenv("SFR:CCPR2L")
.................... #byte   CCP_2_HIGH=                     getenv("SFR:CCPR2H")
.................... #word   CCP_3    =                      getenv("SFR:CCPR3L")
.................... #byte   CCP_3_LOW=                      getenv("SFR:CCPR3L")
.................... #byte   CCP_3_HIGH=                     getenv("SFR:CCPR3H")
.................... #word   CCP_4    =                      getenv("SFR:CCPR4L")
.................... #byte   CCP_4_LOW=                      getenv("SFR:CCPR4L")
.................... #byte   CCP_4_HIGH=                     getenv("SFR:CCPR4H")
.................... #word   CCP_5    =                      getenv("SFR:CCPR5L")
.................... #byte   CCP_5_LOW=                      getenv("SFR:CCPR5L")
.................... #byte   CCP_5_HIGH=                     getenv("SFR:CCPR5H")
.................... 
.................... ////////////////////////////////////////////////////////////////// SPI
.................... // SPI Functions: SETUP_SPI, SPI_WRITE, SPI_READ, SPI_DATA_IN
.................... // Constants used in SETUP_SPI() are:
.................... #define SPI_MASTER               0x20
.................... #define SPI_SLAVE                0x24
.................... #define SPI_SCK_IDLE_HIGH        0x10
.................... #define SPI_SCK_IDLE_LOW         0x00
.................... #define SPI_CLK_DIV_4            0x00
.................... #define SPI_CLK_DIV_16           0x01
.................... #define SPI_CLK_DIV_64           0x02
.................... #define SPI_CLK_T2               0x03
.................... #define SPI_SS_DISABLED          0x01
.................... 
.................... #define SPI_XMIT_IDLE_TO_ACTIVE  0x0000
.................... #define SPI_XMIT_ACTIVE_TO_IDLE  0x4000
.................... 
.................... #define SPI_SAMPLE_AT_MIDDLE     0x0000
.................... #define SPI_SAMPLE_AT_END        0x8000
.................... 
.................... //The following are provided for compatibility
.................... #define SPI_L_TO_H       SPI_SCK_IDLE_LOW
.................... #define SPI_H_TO_L       SPI_SCK_IDLE_HIGH
.................... #define SPI_XMIT_L_TO_H  SPI_XMIT_ACTIVE_TO_IDLE
.................... 
.................... ////////////////////////////////////////////////////////////////// UART
.................... // Constants used in setup_uart() are:
.................... // FALSE - Turn UART off
.................... // TRUE  - Turn UART on
.................... #define UART_ADDRESS           2
.................... #define UART_DATA              4
.................... #define UART_AUTODETECT        8
.................... #define UART_AUTODETECT_NOWAIT 9
.................... #define UART_WAKEUP_ON_RDA     10
.................... #define UART_SEND_BREAK        13
.................... ////////////////////////////////////////////////////////////////// COMP
.................... // Comparator Variables: C1OUT, C2OUT
.................... // Constants used in setup_comparator() are:
.................... //
.................... #define NC_NC_NC_NC   0x404
.................... #define NC_NC         0x404
.................... 
.................... //Pick one constant for COMP1
.................... #define CP1_A0_A3        0x4000080
.................... #define CP1_A1_A3        0x0100081
.................... #define CP1_B3_A3        0x0200082
.................... #define CP1_B1_A3        0x0400083
.................... #define CP1_A0_VREF      0x4000084
.................... #define CP1_A1_VREF      0x0100085
.................... #define CP1_B3_VREF      0x0200086
.................... #define CP1_B1_VREF      0x0400087
.................... //Optionally OR with one or both of the following
.................... #define CP1_OUT_ON_A4    0x2000020
.................... #define CP1_INVERT       0x0000010
.................... #define CP1_FAST         0x0000008
.................... 
.................... //OR with one constant for COMP2
.................... #define CP2_A0_A2        0x4008000
.................... #define CP2_A1_A2        0x0108100
.................... #define CP2_B3_A2        0x0208200
.................... #define CP2_B1_A2        0x0408300
.................... #define CP2_A0_VREF      0x4008400
.................... #define CP2_A1_VREF      0x0108500
.................... #define CP2_B3_VREF      0x0208600
.................... #define CP2_B1_VREF      0x0408700
.................... //Optionally OR with one or both of the following
.................... #define CP2_OUT_ON_A5   0x0082000
.................... #define CP2_INVERT       0x0001000
.................... #define CP2_FAST         0x0000800
.................... 
.................... #bit C1OUT = 0xF79.6
.................... #bit C2OUT = 0xF78.6
.................... 
.................... ////////////////////////////////////////////////////////////////// VREF
.................... // Constants used in setup_low_volt_detect() are:
.................... //
.................... #define LVD_LVDIN   0x1F
.................... #define LVD_47      0x1E
.................... #define LVD_43      0x1D
.................... #define LVD_41      0x1C
.................... #define LVD_38      0x1B
.................... #define LVD_36      0x1A
.................... #define LVD_34      0x19
.................... #define LVD_32      0x18
.................... #define LVD_29      0x17
.................... #define LVD_28      0x16
.................... #define LVD_27      0x15
.................... #define LVD_25      0x14
.................... #define LVD_24      0x13
.................... #define LVD_22      0x12
.................... #define LVD_20      0x11
.................... #define LVD_18      0x10
.................... 
.................... #define LVD_TRIGGER_BELOW 0
.................... #define LVD_TRIGGER_ABOVE 0x80
.................... 
.................... ////////////////////////////////////////////////////////////////// DAC
.................... // Digital to Analog Functions: SETUP_DAC(), DAC_WRITE()
.................... // Constants used in SETUP_DAC() are:
.................... #define DAC_OFF  0
.................... #define DAC_VSS_VDD   0x80
.................... #define DAC_VREF_VDD  0x81
.................... #define DAC_VSS_VREF  0x84
.................... #define DAC_VREF_VREF 0x85
.................... #define DAC_VSS_FVR   0x88
.................... #define DAC_FVR_VREF  0x89
.................... // The following may be OR'ed in with the above using |
.................... #define DAC_OUTPUT    0x20
.................... #define DAC_LVP_POS   0x40
.................... #define DAC_LVP_NEG   0
.................... 
.................... 
.................... ////////////////////////////////////////////////////////////////// INTERNAL RC
.................... // Constants used in setup_oscillator() are:
.................... #define OSC_PLL_ON  0x4000
.................... #define OSC_PLL_OFF 0
.................... #define OSC_31250   0x8000
.................... #define OSC_250KHZ  0x10
.................... #define OSC_500KHZ  0x20
.................... #define OSC_1MHZ    0x30
.................... #define OSC_2MHZ    0x40
.................... #define OSC_4MHZ    0x50
.................... #define OSC_8MHZ    0x60
.................... #define OSC_16MHZ   0x70
.................... #define OSC_32MHZ   0x4060
.................... #define OSC_64MHZ   0x4070
.................... // The following may be OR'ed in with the above using |
.................... #define OSC_TIMER1  1
.................... #define OSC_INTRC   2
.................... #define OSC_NORMAL  0
.................... // The following may be OR'ed in with the above using |
.................... #define OSC_IDLE_MODE  0x80
.................... // A second optional parameter may be used with this part to fine
.................... // tune the speed (signed int,0-31)
.................... // Result may be (ignore all other bits)
.................... #define OSC_STATE_STABLE 4
.................... #define OSC_STATE_EXT_RUNNING 8
.................... 
.................... 
.................... ////////////////////////////////////////////////////////////////// ADC
.................... // ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
.................... //                SET_ADC_CHANNEL(), READ_ADC()
.................... // Constants used for SETUP_ADC() are:
.................... #define ADC_OFF               0           // ADC Off
.................... #define ADC_CLOCK_DIV_2   0x100
.................... #define ADC_CLOCK_DIV_4    0x04
.................... #define ADC_CLOCK_DIV_8    0x01
.................... #define ADC_CLOCK_DIV_16   0x05
.................... #define ADC_CLOCK_DIV_32   0x02
.................... #define ADC_CLOCK_DIV_64   0x06
.................... #define ADC_CLOCK_INTERNAL 0x07           // Internal 2-6us
.................... // The following may be OR'ed in with the above using |
.................... #define ADC_TAD_MUL_0      0x00
.................... #define ADC_TAD_MUL_2      0x08
.................... #define ADC_TAD_MUL_4      0x10
.................... #define ADC_TAD_MUL_6      0x18
.................... #define ADC_TAD_MUL_8      0x20
.................... #define ADC_TAD_MUL_12     0x28
.................... #define ADC_TAD_MUL_16     0x30
.................... #define ADC_TAD_MUL_20     0x38
.................... 
.................... // Constants used in SETUP_ADC_PORTS() are:
.................... #define sAN0         0x10000       //| A0   \\!"K50"
.................... #define sAN1         0x20000       //| A1   \\!"K50"
.................... #define sAN2         0x40000       //| A2   \\!"K50"
.................... #define sAN3         0x80000       //| A4
.................... #define sAN4         0x100000      //| C0
.................... #define sAN5         0x200000      //| C1
.................... #define sAN6         0x400000      //| C2
.................... #define sAN7         0x800000      //| C3
.................... #define sAN8         0x1           //| C6
.................... #define sAN9         0x2           //| C7
.................... #define sAN10        0x4           //| B4
.................... #define sAN11        0x8           //| B5
.................... #define NO_ANALOGS      0       // None
.................... #define ALL_ANALOG   0xF00FF    // A0 A1 A2 A4 C0 C1 C2 C3 C6 C7 B4 B5
.................... 
.................... // One of the following may be OR'ed in with the above using |
.................... #define VSS_VDD               0x000          // Range 0-Vdd
.................... #define VREF_VREF             0x500          // Range VrefL-VrefH
.................... #define VSS_VREF              0x400          // Range 0-VrefH
.................... #define VREF_VDD              0x100          // Range VrefL-Vdd
.................... 
.................... 
.................... // Constants used in READ_ADC() are:
.................... #define ADC_START_AND_READ     7   // This is the default if nothing is specified
.................... #define ADC_START_ONLY         1
.................... #define ADC_READ_ONLY          6
.................... 
.................... 
.................... 
.................... 
.................... 
.................... ////////////////////////////////////////////////////////////////// INT
.................... // Interrupt Functions: ENABLE_INTERRUPTS(), DISABLE_INTERRUPTS(),
.................... //                      CLEAR_INTERRUPT(), INTERRUPT_ACTIVE(),
.................... //                      EXT_INT_EDGE()
.................... //
.................... // Constants used in EXT_INT_EDGE() are:
.................... #define L_TO_H              0x40
.................... #define H_TO_L                 0
.................... // Constants used in ENABLE/DISABLE_INTERRUPTS() are:
.................... #define GLOBAL                    0xF2C0
.................... #define PERIPH                    0xF240
.................... #define INT_RTCC                  0x00F220
.................... #define INT_TIMER0                0x00F220
.................... #define INT_TIMER1                0x009D01
.................... #define INT_TIMER2                0x009D02
.................... #define INT_TIMER3                0x00A002
.................... #define INT_EXT_L2H               0x5000F210
.................... #define INT_EXT_H2L               0x6000F210
.................... #define INT_EXT                   0x00F210
.................... #define INT_EXT1_L2H              0x5001F008
.................... #define INT_EXT1_H2L              0x6001F008
.................... #define INT_EXT1                  0x00F008
.................... #define INT_EXT2_L2H              0x5002F010
.................... #define INT_EXT2_H2L              0x6002F010
.................... #define INT_EXT2                  0x00F010
.................... #define INT_RB                    0x01FFF208
.................... #define INT_AD                    0x009D40
.................... #define INT_RDA                   0x009D20
.................... #define INT_TBE                   0x009D10
.................... #define INT_SSP                   0x009D08
.................... #define INT_CCP1                  0x009D04
.................... #define INT_CCP2                  0x00A001
.................... #define INT_BUSCOL                0x00A008
.................... #define INT_COMP                  0x00A040
.................... #define INT_EEPROM                0x00A010
.................... #define INT_TBE2                  0x00A310
.................... #define INT_RDA2                  0x00A320
.................... #define INT_OSCF                  0x00A080
.................... #define INT_HLVD                  0x00A004
.................... #define INT_BUSCOL2               0x00A340
.................... #define INT_COMP2                 0x00A020
.................... #define INT_SSP2                  0x00A380
.................... #define INT_TIMER4                0x007D01
.................... #define INT_TIMER5                0x007D02
.................... #define INT_TIMER6                0x007D04
.................... #define INT_CCP3                  0x007A01
.................... #define INT_CCP4                  0x007A02
.................... #define INT_CCP5                  0x007A04
.................... #define INT_TMR1G                 0x00A301
.................... #define INT_TMR3G                 0x00A302
.................... #define INT_TMR5G                 0x00A304
.................... #define INT_CTMU                  0x00A308
.................... #define INT_RB4                   0x010F208
.................... #define INT_RB5                   0x020F208
.................... #define INT_RB6                   0x040F208
.................... #define INT_RB7                   0x080F208
.................... 
.................... #list
.................... 
.................... #fuses INTRC_IO, NOWDT, NOBROWNOUT, NOPUT, NOLVP, NOMCLR, PLLEN 
.................... #USE delay(internal=16Mhz, clock=64Mhz) 
*
000C6:  CLRF   FEA
000C8:  MOVLW  1C
000CA:  MOVWF  FE9
000CC:  MOVF   FEF,W
000CE:  BZ    00EC
000D0:  MOVLW  14
000D2:  MOVWF  01
000D4:  CLRF   00
000D6:  DECFSZ 00,F
000D8:  BRA    00D6
000DA:  DECFSZ 01,F
000DC:  BRA    00D4
000DE:  MOVLW  BF
000E0:  MOVWF  00
000E2:  DECFSZ 00,F
000E4:  BRA    00E2
000E6:  BRA    00E8
000E8:  DECFSZ FEF,F
000EA:  BRA    00D0
000EC:  GOTO   015C (RETURN)
.................... 
.................... 
.................... #use RS232 (STREAM=PC_SERIAL, baud=115200, UART1, ERRORS) 
.................... 
.................... ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
.................... // Interrupts 
.................... ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
.................... #INT_RDA 
.................... void pc_comms_isr() { 
....................    fprintf(PC_SERIAL, "B"); 
*
000AE:  MOVLW  42
000B0:  BTFSS  F9E.4
000B2:  BRA    00B0
000B4:  MOVWF  FAD
.................... } 
.................... 
.................... 
000B6:  BCF    F9E.5
000B8:  GOTO   0060
.................... void main () { 
*
00114:  CLRF   FF8
00116:  BCF    FD0.7
00118:  BSF    07.7
0011A:  CLRF   FEA
0011C:  CLRF   FE9
0011E:  MOVLW  70
00120:  MOVWF  FD3
00122:  MOVLW  40
00124:  MOVWF  F9B
00126:  MOVF   FD3,W
00128:  CLRF   19
0012A:  BSF    FB8.3
0012C:  MOVLW  8A
0012E:  MOVWF  FAF
00130:  MOVLW  00
00132:  MOVWF  FB0
00134:  MOVLW  A6
00136:  MOVWF  FAC
00138:  MOVLW  90
0013A:  MOVWF  FAB
0013C:  MOVLW  00
0013E:  MOVWF  F7E
00140:  BCF    FC1.0
00142:  BCF    FC1.1
00144:  BCF    FC1.2
00146:  BCF    FC1.3
00148:  MOVLW  00
0014A:  MOVWF  F7F
0014C:  CLRF   F78
0014E:  CLRF   F79
00150:  CLRF   1A
....................    int8 i = 0x00; 
....................    //setup_oscillator(OSC_64MHZ|OSC_INTRC); 
....................     
....................    delay_ms(1000); 
00152:  MOVLW  04
00154:  MOVWF  1B
00156:  MOVLW  FA
00158:  MOVWF  1C
0015A:  BRA    00C6
0015C:  DECFSZ 1B,F
0015E:  BRA    0156
....................     
....................    fprintf(PC_SERIAL, "Started!"); 
00160:  MOVLW  BC
00162:  MOVWF  FF6
00164:  MOVLW  00
00166:  MOVWF  FF7
00168:  BRA    00F0
....................     
....................     
....................    enable_interrupts(INT_RDA); 
0016A:  BSF    F9D.5
....................    enable_interrupts(GLOBAL); 
0016C:  MOVLW  C0
0016E:  IORWF  FF2,F
.................... 
....................    while (TRUE) {} 
00170:  BRA    0170
.................... }
00172:  SLEEP

Configuration Fuses:
   Word  1: F800   INTRC_IO PLLEN FCMEN PRIMARY IESO
   Word  2: 3C19   NOBROWNOUT NOWDT NOPUT BORV20 WDT32768
   Word  3: 3F00   NOMCLR PBADEN NODELAYINTOSC CCP2B5 CCP2C1 TIMER3C0 LPT1OSC
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST
   Word  5: C00F   NOPROTECT NOCPB NOCPD
   Word  6: E00F   NOWRT NOWRTC NOWRTD NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB


I couldn't see anything obvious where it was disabling the analog features, so I added this and still nothing:

Code:

.........
   delay_ms(1000);
   #asm
   MOVLW  0xFC
   MOVWF  0xF3A
   #endasm
   fprintf(PC_SERIAL, "Started!");
.........
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 1:25 pm     Reply with quote

The CCS command is setup_adc_ports(NO_ANALOGS);

It's definitely using the UART.

Have you tried a slower baud rate?. Look at the chip's errata. It can miss the start bit, unless BRGH=1 and BRG16=1. I don't know if your baud rate is possible within this restriction.....

Best Wishes
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Thu Jan 31, 2013 1:23 am     Reply with quote

Thanks Ttelmah,

Fixed by upgrading to 4.125.
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