void spiTest() { int i, j; csInit (); // Initialize chip select PC03 spiInit (SPI1); for (i = 0; i < 8; i++) { for (j = 0; j < 4; j++) txbuf [j] = i*4 + j; GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 0); spiReadWrite (SPI1 , rxbuf , txbuf , 4, SPI_SLOW ); GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 1); for (j = 0; j < 4; j++) if (rxbuf [j] != txbuf [j]) assert_failed (__FILE__ , __LINE__ ); } for (i = 0; i < 8; i++) { for (j = 0; j < 4; j++) txbuf16 [j] = i*4 + j + (i << 8); GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 0); spiReadWrite16 (SPI1 , rxbuf16 , txbuf16 , 4, SPI_SLOW ); GPIO_WriteBit (GPIOE , GPIO_Pin_3 , 1); for (j = 0; j < 4; j++) if ( rxbuf16 [j] != txbuf16 [j]) assert_failed (__FILE__ , __LINE__ ); } }
void spiTest2() { csInit (); spiInit(SPI1); while(1){ GPIOE->BSRRH |= GPIO_Pin_3; // set PE3 (CS) low SPI1_send(0xAA); // transmit data received_val = SPI1_send(0x00); // transmit dummy byte and receive data GPIOE->BSRRL |= GPIO_Pin_3; // set PE3 (CS) high } }
///////////////////////////////////////////// // http://www.lxtronic.com/index.php/basic-spi-simple-read-write ///////////////////////////////////////////// void spiTestMems () { csInit (); spiInit(SPI1); int8_t data; mySPI_SendData(0x20, 0xC0); //LIS302D Config while(1) { data = mySPI_GetData(0x29); } }
BuildDNA( long version, GlobalFunc *global, LWModCommand *local, void *serverData) { ModData *md; if ( version != LWMODCOMMAND_VERSION ) return AFUNC_BADVERSION; if ( !get_user( global )) return AFUNC_OK; userabort = 0; if ( md = csInit( global, local )) { getlayers(); setsurf(); meshedit(); if ( !userabort ) cmdedit(); csDone(); } return AFUNC_OK; }
int main(int argc, char* argv[]) { csInit (); spiInit(SPI1); mySPI_SendData(Ctrl_Reg1, 0x40); //0x40 = 0100000, 0xC0 = 11000000 = 400 Hz output data rate), active uart_open(myUSART, 9600, 0); uint8_t ri; cmdi = 0; timInit(); // Infinite loop while (1) { } uart_close(myUSART); }