Esempio n. 1
0
int SPI1_transfer( int data)
{
    LATBbits.LATB0 = 0;     // set pin RB0 low / disable latch
    while (TxBufFullSPI1());	// ensure buffer is free before writing
    WriteSPI1(data);			// send the data through SPI
    while (SPI1STATbits.SPIBUSY); // blocking wait for end of transaction
    LATBbits.LATB0 = 1;     // set pin RB0 high / enable latch
}
Esempio n. 2
0
//instead of writing SPI code repeatedly, made a function.
//Used various chip selects on the same channel to change
//values of various different digital potentiometers
void deliverSPICh1Datum(int datum){
    // test for ready
     while (TxBufFullSPI1());
     // write to spi2
     WriteSPI1(Digipot_config_chan_A | datum);
    // test for done
    while (SPI1STATbits.SPIBUSY); // wait for end of transaction
     // CS high
    // mPORTBSetBits(BIT_4); // end transaction
}