// Master talks to Cry Detect Board (CDB) void spiMaster_Init(void) { // Open the SPI driver. DrvSPI_Open(SPI_MASTER_HANDLER, SPI_MASTER_OPEN_FLAGS, SPI_MASTER_DIVIDER); // Select the slave. DrvSPI_SlaveSelect(SPI_MASTER_HANDLER, TRUE, DRVSPI_IDEL_CLK_LOW); DrvSPI_SelectSlave(SPI_MASTER_HANDLER, SPI_MASTER_DEVICE); // Read/write data in 16 bit chunks. DrvSPI_SetDataConfig(SPI_MASTER_HANDLER, 1, 16); }
void init_SPI3(void) { DrvGPIO_Open(E_GPB, 9, E_IO_OUTPUT); DrvGPIO_Open(E_GPB, 7, E_IO_OUTPUT); DrvGPIO_Open(E_GPB, 10, E_IO_OUTPUT); DrvGPIO_Open(E_GPD, 14, E_IO_OUTPUT); DrvGPIO_ClrBit(E_GPD, 14); DrvGPIO_InitFunction(E_FUNC_SPI3); /* Configure SPI3 as a master, Type1 waveform, 8-bit transaction */ DrvSPI_Open(eDRVSPI_PORT3, eDRVSPI_MASTER, eDRVSPI_TYPE1, 8); /* MSB first */ DrvSPI_SetEndian(eDRVSPI_PORT3, eDRVSPI_MSB_FIRST); /* Disable the automatic slave select function of SS0. */ DrvSPI_DisableAutoSS(eDRVSPI_PORT3); /* Set the active level of slave select. */ DrvSPI_SetSlaveSelectActiveLevel(eDRVSPI_PORT3, eDRVSPI_ACTIVE_LOW_FALLING); /* SPI clock rate 20MHz */ DrvSPI_SetClockFreq(eDRVSPI_PORT3, 25000000, 0); SPI_CS_SET; }
void spiSlave_Init(void) { // Open the SPI driver. DrvSPI_Open(SPI_SLAVE_HANDLER, SPI_SLAVE_OPEN_FLAGS, SPI_SLAVE_DIVIDER); // Configure for slave mode. DrvSPI_SPI1_SetSlaveMode(TRUE); // Level trigger for slave mode. DrvSPI_SPI1_LevelTriggerInSlave(TRUE); // Set the zero status byte to shift out. DrvSPI_SingleWriteData0(SPI_SLAVE_HANDLER, (UINT32) 0x00); // Initiate the SPI transaction. DrvSPI_SetGo(SPI_SLAVE_HANDLER); // Enable interupt on SPI CS falling. DrvGPIO_SetFallingInt(&SPI_SLAVE_GPIO, SPI_SLAVE_CS_PIN, TRUE); sway_state = NO_STATE; }