PIC18F26J13, SPI2 mapped on PORTB, doesnt work

358 views Asked by At

I am working on a project with a 18f26j13, where i need I2C on MSSP1, and SPI on MSSP2. my I2C works perfectly, but i cant get the SPI to work on port B, if i map them to port c, it works perfectly, so i am thinking that there is something i am not disabling on port b.

I remap the pins to port B, and sets the pins as digital i/o in ANCON, and ofc sets the tris bit for RB4

i have a feeling i have tried everything, but that i am missing something obvious, and i am really hoping someone can help :)

EDIT: ohh i forgot... i can meassure a clock on SCK2/RB3, and pulses on SDO2/RB5, so i looks like the problem is with RB4...

EDIT2: Well i was wrong, the problem is with RB5, if i map SDO2 to RB2, then it works, still a problem though since kinda have to attach it to RB5...

void peripheral_init(void)
{

//disabler alle ADC
ADCON0 = 0b00000000;    //adc disabled, ref = Vss,Vdd
ANCON0 = 0b11111111;    //alle adc kanaler disabled
ANCON1 = 0b00011111;    //alle adc kanaler disabled
ADCON1 = 0b10111110;    //

//disabling comperator
CM1CON = 0b00000000;
CM2CON = 0b00000000;
CM3CON = 0b00000000;

//mapping SPI2 to portb
PPSUnLock()

iPPSInput(IN_FN_PPS_SDI2,IN_PIN_PPS_RP7); //RB4
iPPSInput(IN_FN_PPS_SCK2IN,IN_PIN_PPS_RP6); //RB3

iPPSOutput(OUT_PIN_PPS_RP6,OUT_FN_PPS_SCK2); //RB3
iPPSOutput(OUT_PIN_PPS_RP8,OUT_FN_PPS_SDO2); //RB5

PPSLock();

//port setup
TRISA = 0b00000011;
LATA = 0b00000000;

TRISB = 0b00010010;
LATB = 0b00010000;

TRISC = 0b10010000; //bit 3+4 = i2c bit 7 = uart1 rx
LATC = 0b00000000;
}


void interupt_init(void)
{
INTCON = 0b00000000;
INTCON2 = 0b10000000; //disabling the weak pullup on portb
INTCON3 = 0b00000000;
}

void SpiInit(void)
{
    nCS = 1;        
    SSP2STAT = 0xC0;
    SSP2CON1 = 0b00110000;  // Timer2 output 400KHz
}
0

There are 0 answers