|
|
View previous topic :: View next topic |
Author |
Message |
Bollo
Joined: 01 Dec 2010 Posts: 25
|
PIC18F47J53 PPS non functional [SOLVED] |
Posted: Fri Jul 15, 2011 6:07 pm |
|
|
Hello, I'm having a problem with PPS and pin remapping on a PIC18F47J53 with CCS PCH 4.120. I cannot get any pins whatsoever to remap. I have tried both the simple #PIN_SELECT directive and also setting the registers manually using ASM. I'm primarily trying to remap MSSP2 for SPI2 onto 3 pins (SDO2=C0, SDI2=C1, SCK2=C2) and then ECCP PWM outputs onto others (in this example just CCP1=B0). Here is my code please let me know if you can see anything wrong with this as I can't see why it wouldn't be working :S. Many thanks.
Code: |
#include <18F47J53.h>
#device adc=12
#FUSES NOWDT //No Watch Dog Timer
#FUSES PLL2 //No PLL PreScaler
#FUSES PLLEN
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES DEBUG //No Debug mode for ICD
#FUSES NOCPUDIV
#FUSES NOPROTECT //Code not protected from reading
#FUSES INTRC_PLL_IO
#FUSES NOCLOCKOUT
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES DSWDTOSC_INT
#FUSES RTCOSC_T1
#FUSES DSBOR
#FUSES DSWDT
#FUSES DSWDT2147483648
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES ADC12
#FUSES MSSPMSK7
#FUSES WPFP
#FUSES NOWPCFG
#FUSES WPDIS
#FUSES WPBEG
#FUSES LS48MHZ
#use delay(clock=48000000)
//Commented out while using setup_spi2
//#use spi(spi2,master,bits=8,FORCE_HW,STREAM=SPI)
//#use spi(MASTER, MODE=0, DI=PIN_C1, DO=PIN_C0, CLK=PIN_C2, BITS=8,STREAM=SPI)
//Commented out while manipulating registers
//#PIN_SELECT SDO2=PIN_C0
//#PIN_SELECT SDI2=PIN_C1
//#PIN_SELECT SCK2OUT=PIN_C2
//#PIN_SELECT P1A=PIN_B0
//Register defines
#define EECON2 0xFA7
#define RPOR11 0xECB
#define RPOR13 0xECD
#define RPOR03 0xEC3
#define RPINR21 0xEFC
#define PPSCON 0xEBF
#define IOLOCK 0x00
#define INTCON 0xFF2
#define GIE 0x07
//Commented for debugging
//#include <usb_cdc.h>
//#include <stdlib.h>
//#include <string.h>
void startup(){
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_timer_2( T2_DIV_BY_4, 0xc0, 2);
setup_ccp1(CCP_PWM);
setup_spi2(SPI_MASTER | spi_h_to_l | spi_clk_div_16);
output_high(PIN_E1); //GPU_CS
delay_ms(200);
}
void manual_pps(){
//adapted from example 10-7 in the datasheet
#asm
MOVLB 0x0E //PPS registers in BANK 14
BCF INTCON, GIE //disable interrupts
//UNLOCK
MOVLW 0x55 // 1st unlock code
MOVWF EECON2 // 1st unlock code into EECON2
MOVLW 0xAA // 2nd unlock code
MOVWF EECON2 // 2nd unlock code into EECON2
BCF PPSCON, IOLOCK // Clear IOLOCK of PPSCON, unlocking PPS
//REMAP PINS
MOVLW 0x0A // value 10 (SDO2)
MOVWF RPOR11
MOVLW 0x0E // value 14 (CCP1)
MOVWF RPOR03
MOVLW 0x0B // value 11 (SCLK2 Output)
MOVWF RPOR13
MOVLW 0x0C // RP12 / C2
MOVWF RPINR21 // RPINR21 to assign SDI2 Input
//LOCK
BCF INTCON, GIE
MOVLW 0x55 // 1st lock code
MOVWF EECON2
MOVLW 0xAA // 2nd lock code
MOVWF EECON2
BSF PPSCON, IOLOCK // Set IOLOCK of PPSCON, locking PPS
#endasm
delay_ms(100);
}
void main()
{
startup();
manual_pps();
set_pwm1_duty(200);
do{
output_low(PIN_E1);
/* Commented while not using #use_spi
spi_xfer(SPI,"A");
spi_xfer(SPI,"D");
spi_xfer(SPI,"C");
spi_xfer(SPI,"¬");
*/
spi_write2("A");
output_high(PIN_E1);
delay_ms(500);
}
while(1);
}
|
Last edited by Bollo on Sat Jul 16, 2011 12:38 pm; edited 1 time in total |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Jul 15, 2011 6:42 pm |
|
|
If I simplify your code to this:
Code: |
#include <18F47J53.h>
#device adc=12
#FUSES NOWDT //No Watch Dog Timer
#FUSES PLL2 //No PLL PreScaler
#FUSES PLLEN
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES DEBUG //No Debug mode for ICD
#FUSES NOCPUDIV
#FUSES NOPROTECT //Code not protected from reading
#FUSES INTRC_PLL_IO
#FUSES NOCLOCKOUT
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES DSWDTOSC_INT
#FUSES RTCOSC_T1
#FUSES DSBOR
#FUSES DSWDT
#FUSES DSWDT2147483648
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES ADC12
#FUSES MSSPMSK7
#FUSES WPFP
#FUSES NOWPCFG
#FUSES WPDIS
#FUSES WPBEG
#FUSES LS48MHZ
#use delay(clock=48000000)
#PIN_SELECT SDO2=PIN_C0
#PIN_SELECT SDI2=PIN_C1
#PIN_SELECT SCK2OUT=PIN_C2
#PIN_SELECT P1A=PIN_B0
void main() {
setup_oscillator(OSC_8MHZ | OSC_PLL_ON);
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_timer_2( T2_DIV_BY_4, 0xc0, 2);
setup_ccp1(CCP_PWM);
setup_spi2(SPI_MASTER | spi_h_to_l | spi_clk_div_16);
output_high(PIN_E1); //GPU_CS
delay_ms(200);
set_pwm1_duty(200);
while(1);
|
I get this:
Code: | 00032: MOVLB E
00034: MOVLW 55
00036: MOVWF EECON2
00038: MOVLW AA
0003A: MOVWF EECON2
0003C: BCF xBF.0
0003E: MOVLW 0C
00040: MOVWF xFC
00042: MOVLW 0E
00044: MOVWF xC3
00046: MOVLW 0A
00048: MOVWF xCB
0004A: MOVLW 0B
0004C: MOVWF xCD
0004E: MOVLW 55
00050: MOVWF EECON2
00052: MOVLW AA
00054: MOVWF EECON2
00056: BSF xBF.0 |
This right here is the unlock/set/relock sequence.
I'm using PCH 4.122
also, to do it in your own ASM, I remember needing the line to be:
#ASM ASIS
Otherwise it CCS would abbreviate/combine some of my ASM.
I helped originally debug the 18F46J11 which has problems, so I went through some of what you're going through... but I've also used the 47j53 for another project. (admittedly without any #PIN_SELECT's)
Check your .LST file to see if you get the right handshake.
I'll also let you verify all those locations are the right RPIN or RPOUT registers being set with the right values.
Otherwise, I've seen #pin_select work just fine in the past.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Bollo
Joined: 01 Dec 2010 Posts: 25
|
|
Posted: Fri Jul 15, 2011 7:49 pm |
|
|
Thanks for the rapid reply, it's truly aprreciated.
This is what is in the lst, so its the same as your compiler which I suppose means the compiler is not at fault.
Code: |
0002E: CLRF FF8
00030: BCF FD0.7
00032: MOVLB E
00034: MOVLW 55
00036: MOVWF FA7
00038: MOVLW AA
0003A: MOVWF FA7
0003C: BCF xBF.0
0003E: MOVLW 0C
00040: MOVWF xFC
00042: MOVLW 0E
00044: MOVWF xC3
00046: MOVLW 0A
00048: MOVWF xCB
0004A: MOVLW 0B
0004C: MOVWF xCD
0004E: MOVLW 55
00050: MOVWF FA7
00052: MOVLW AA
00054: MOVWF FA7
00056: BSF xBF.0
|
I know the signal tracks themselves on the PCB are fine as i can pass software SPI over them and it behaves as expected albeit with a max baud of 800Kbit. I have also double checked the pin assignments and they are also correct, I'm after SDO2 on RP11/C0 SDI2 on RP12/C1 and SCK2 on RP13/C2 and CCP1 on RP3/B0. Sadly I get no output from the CCP (in PWM mode) or anything from MSSP2. So it seems I should start trawling through the errata for the chip.
Edit: The errata is surprisingly short and mentions nothing useful. I must be doing something very silly
Code: |
#PIN_SELECT SDO2=PIN_C0
#PIN_SELECT SDI2=PIN_C1
#PIN_SELECT SCK2OUT=PIN_C2
#PIN_SELECT P1A=PIN_B0
|
Just to be absolutely clear I should be able to use the above code to remap the pins (the peripheral names are given in the CCS manual) and then use
Code: |
setup_spi2(SPI_MASTER | spi_h_to_l | spi_clk_div_16);
spi_write2(5);
setup_ccp1(CCP_PWM);
set_pwm1_duty(200);
|
To use the second MSSP and utilise the CCP in PWM mode, simple as that? |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Jul 15, 2011 8:24 pm |
|
|
Oh!
My bad. I forgot to say: You need to set the TRIS register for OUTPUT for any pin that's an output.
So for your your SCP and P1A pins:
I think for simplicity's sake:
output_drive (PIN_C2);
output_drive (PIN_B0);
should work -- give it a shot and let me know.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Bollo
Joined: 01 Dec 2010 Posts: 25
|
|
Posted: Sat Jul 16, 2011 3:06 am |
|
|
That was it! I had completly overlooked setting TRIS, I had vaguely assumed that it was done automatically somewhere when using #PIN_SELECT. Many thanks, I now have both my CCPs and HW SPI working perfectly. Bah, knew it would be something simple and silly. I suppose I'll never forget it now! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sat Jul 16, 2011 7:36 am |
|
|
fabulous.
If you would, change the original subject of this thread to include [SOLVED] so other people can find it faster.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|
|
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
|