Hi guys,
I posted previously when I was trying to get the PIC24 spi module to work. (The device is an FJ128GA006).
My issue now is driving the SS pin low. I am addressing the Microchip MCP4921 DAC, so communication is 1-way and I'm operating the SPI module in master mode.
At the moment, I am driving the SS pin low by instruction before calling my SPI function. I then run a "for-loop" before setting the SS pin high again - by instruction.
Surely, the SPI module should take care of this? Me confused.
My initialization code is as follows:
Any insight will be appreciated.
Thanks.
void spiInit()
{
SPI2BUF = 0;
SPI2CON1 = 0;
SPI2CON2 = 0;
SPI2STAT = 0;
SPI2STATbits.SPIROV = 0; // clear overflow bit
SPI2CON1bits.MODE16 = 1; // configure words as 16-bit
SPI2CON1bits.MSTEN = 1; // set as master
SPI2CON1bits.CKP = 0; // set clock idle state
SPI2CON1bits.CKE = 0;
SPI2CON1bits.DISSCK = 0; // enable internal clock
SPI2CON1bits.SPRE = 4; // configure secondary clock prescaler
SPI2CON1bits.PPRE = 1; // configure primary clock prescaler
SPI2CON1bits.SSEN = 1;
SPI2STATbits.SPIEN = 1; // enable spi module
}