Reputation: 434
Hello I need to communicate with a Dual DAC by using SPI. DAC : DAC
I use PIC 18F26K83. I will only transmit data to the DAC, I will not receive anything. This is how I made the connections between my PIC and DAC( see the image attached). So my question is related to PPS mapping and pin configurations: RC7 connected to DIN pin of DAC, RC6 connected to
Do I need to map my pins as inputs also? This is how I did the PPS mapping but I m not really sure:
I used RxyPPS register (Page: 267) in order to set my pins as output sources by using table 17-2 (Page:268)
RC7PPS= 0b00011111 ; //DIN, RC7 = SDIPPS
RC6PPS= 0b00100000; //CS, RC6= SSPPS
RC5PPS= 0b00011110; //SCLK, RC5=SCKPPS
So I believe this is enough for setting them as output. Do I also need to set them as inputs?
I know it does not make sense but I m confused about using RxxxPPS register.
Upvotes: 1
Views: 640
Reputation: 1424
If you are transmitting data to a DAC I would assume that the PIC should be set as SPI master mode - i.e. the SS pin will be unused on the PIC -- So you shouldn't set PPS for RC6 as it is the CS pin for DAC, it should be set as a simple GPIO output
LATCbits.LATC6 = 1; // initialise high
TRISCbits.TRISC6 = 0; // output
You should also add PPS locking/unlocking sequence and might need to set SCLK as an input even if it is one way comms.
// disable interrupts (if req)
INTCON0bits.GIE = 0;
// PPS unlock sequence
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 0; // PPS is not locked
RC7PPS = 0b00011111; // SDO (DAC DIN) RC7
RC5PPS = 0b00011110; //SCLK OUTPUT RC5=SCKPPS
SPI1SCKPPS = 0b00010101; // SCLK INPUT RC5
// PPS lock sequence
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCKbits.PPSLOCKED = 1; // PPS is locked
// enable interrupts (if req)
INTCON0bits.GIE = 1;
An aside - ensure SPI is set to master mode and "Transmit only" mode.
SPI1CON0bits.MST = 1; // bus master
SPI1CON2bits.RXR = 0; // transmit only
SPI1CON2bits.TXR = 1; // transmit only
Upvotes: 1