Example #1
0
static void WaitForDataByte(SpiChannel chn)
{
#if defined (__C32__)
	while (!SpiChnTxBuffEmpty(chn) || !SpiChnDataRdy(chn)); 
#elif defined (__C30__)
	switch(chn)
	{
		case 1:
			while ((SPI1STATbits.SPITBF == 1) || (SPI1STATbits.SPIRBF == 0));
		break;
		case 2:
			while ((SPI2STATbits.SPITBF == 1) || (SPI2STATbits.SPIRBF == 0));
		break;
	}

#endif

}
Example #2
0
int main(void)
{
    initPic32();

    PORTSetPinsDigitalIn(IOPORT_A, BIT_0);
    PORTSetPinsDigitalIn(IOPORT_A, BIT_1);
    PORTSetPinsDigitalIn(IOPORT_B, BIT_14);

    PPSInput(1, SS1, RPA0);
    PPSInput(2, SDI1, RPA1);

#ifndef NO_SDO
    PPSOutput(3, RPA2, SDO1);
#endif

    SpiChnOpen(1, SPI_OPEN_MODE8|SPI_OPEN_SLVEN|SPI_OPEN_SSEN
#ifdef NO_SDO
               |SPI_OPEN_DISSDO
#endif
               , 2);

    init();

    uint8_t lastByteReceived = 0;
    uint8_t cmd[8];
    uint8_t length=0;
    uint8_t toRead = 1;
    while(1) {
        if(SpiChnTxBuffEmpty(1))
            SpiChnPutC(1, lastByteReceived);
        lastByteReceived = 0;

        while(!SpiChnDataRdy(1))
            loop();
        uint8_t byte = SpiChnGetC(1);
        cmd[length++] = byte;
        toRead--;
        if(toRead==0)
            toRead = commandReceived(cmd, length);
    }
}