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__ ); } }
static void LcdWrite16( char dc, const uint16_t *data, int cnt ) { GPIO_WriteBit(LCD_PORT,GPIO_PIN_DC, dc); // dc: 1 = data, 0 = control GPIO_ResetBits(LCD_PORT,GPIO_PIN_SCE); spiReadWrite16(SPILCD, 0, data, cnt, LCDSPEED); GPIO_SetBits(LCD_PORT,GPIO_PIN_SCE); }
int xchng_datablock(SPI_TypeDef *SPIx, int half, const void *tbuf, void *rbuf, unsigned count) { if (count > 4) { if (half) SPI_DataSizeConfig(SPI2, SPI_DataSize_16b); if (!tbuf) { dmaRcvBytes(SPI2, rbuf, count, half); } else if (!rbuf) { dmaTxBytes(SPI2, tbuf, count, half); } else { dmaExgBytes(SPI2, rbuf, tbuf, count, half); } SPI_DataSizeConfig(SPI2, SPI_DataSize_8b); } else { if (half) { spiReadWrite16(SPI2, rbuf, tbuf, count, SPI_FAST); } else { spiReadWrite(SPI2 , rbuf, tbuf ,count , SPI_FAST); } } }