void SPI_LoopbackTest() { SPI_Init(); char i = SPI_Xfer(5); SPI_Close(); FlashLED(i+1); }
void Scan_WriteData(uint16_t valueX, uint16_t valueY) { uint8_t valXL,valYL,valXH,valYH; valYH = (uint8_t)(valueY>>8); valXH = (uint8_t)(valueX>>8); valYL = (uint8_t)valueY; valXL = (uint8_t)valueX; SPI_Open(); SPI_Send(valXH,valYH); SPI_Send(valXL,valYL); SPI_Close(); }
int main(void) { char str[20]; unsigned int channel0; unsigned int channel1; float lux; signal(SIGINT, sigint_handler); //Install signal handler for user interrupt (CTRL-C) SPI_Initialize(); //Initialize SPI peripheral TFT_Initialize(); I2C_Initialize(APDS9300ADDR); //Initialize I2C and setup chip address AL_Initialize(); //Setup Ambient light sensor Image_t LampOn = {_acLampON,100,100}; TFT_Background(WHITE); TFT_DisplayImage(&LampOn,5,5); while(programRunning) { channel0 = AL_ReadChannel(CH0); //Take a reading from channel one channel1 = AL_ReadChannel(CH1); //Take a reading from channel two lux = AL_Lux(channel0,channel1); sprintf(str, "%3.2f Lx ", lux); TFT_PrintString(10,140,RED,WHITE,str,2); delay_ms(1000); } SPI_Close(); bcm2835_close(); return 0; }
int main(void) { SPI_Initialize(); //Initialize SPI peripheral TFT_Initialize(); char texty[] = "Sensorian-123"; while(1) { TFT_Background(WHITE); TFT_SetRotation(PORTRAIT); //Portrait mode TFT_VerticalLine(5,5,90,BLUE); TFT_PrintString(10,80,FOREGROUND,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(PORTRAIT_INV); //Portrait mode TFT_VerticalLine(5,5,90,GREEN); TFT_PrintString(10,80,RED,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(PORTRAIT_REF); //Portrait mode reflected TFT_VerticalLine(5,5,90,YELLOW); TFT_PrintString(10,80,GREEN,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(PORTRAIT_INV_REF); TFT_VerticalLine(5,5,90,RED); //Portrait mode reflected TFT_PrintString(10,80,PURPLE,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(LANDSCAPE); //Landscape mode TFT_VerticalLine(5,5,80,GRAY1); TFT_PrintString(10,80,GREEN,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(LANDSCAPE_REF); //Landscape mode reflected TFT_VerticalLine(5,5,80,PURPLE); TFT_PrintString(10,80,PURPLE,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(LANDSCAPE_INV); //Landscape mode inverted TFT_VerticalLine(5,5,80,NAVY); TFT_PrintString(10,80,RED,BACKGROUND,texty,1); delay_ms(DELAY); TFT_Background(WHITE); TFT_SetRotation(LANDSCAPE_INV_REF); TFT_VerticalLine(5,5,80,PURPLE); TFT_PrintString(10,80,FOREGROUND,BACKGROUND,texty,1); //Landscape mode inverted reflected delay_ms(DELAY); } SPI_Close(); return 0; }
void SPIClass::end() { SPI_Close(spi); }
/* ------------- */ int main(void) { uint32_t u32DataCount; /* Unlock protected registers */ SYS_UnlockReg(); /* Init system, IP clock and multi-function I/O. */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Configure UART0: 115200, 8-bit word, no parity bit, 1 stop bit. */ UART_Open(UART0, 115200); /* Init SPI */ SPI_Init(); printf("\n\n"); printf("+-----------------------------------------------------+\n"); printf("| SPI Master Mode Sample Code |\n"); printf("+-----------------------------------------------------+\n"); printf("\n"); printf("Configure SPI0 as a master.\n"); printf("Bit length of a transaction: 32\n"); printf("The I/O connection for SPI0:\n"); printf(" SPI0_SS0 (PC.0)\n SPI0_CLK (PC.1)\n"); printf(" SPI0_MISO0 (PC.2)\n SPI0_MOSI0 (PC.3)\n\n"); printf("SPI controller will enable FIFO mode and transfer %d data to a off-chip slave device.\n", TEST_COUNT); printf("In the meanwhile the SPI controller will receive %d data from the off-chip slave device.\n", TEST_COUNT); printf("After the transfer is done, the %d received data will be printed out.\n", TEST_COUNT); printf("The SPI master configuration is ready.\n"); for(u32DataCount = 0; u32DataCount < TEST_COUNT; u32DataCount++) { /* Write the initial value to source buffer */ g_au32SourceData[u32DataCount] = 0x00550000 + u32DataCount; /* Clear destination buffer */ g_au32DestinationData[u32DataCount] = 0; } printf("Before starting the data transfer, make sure the slave device is ready. Press any key to start the transfer.\n"); getchar(); printf("\n"); /* Set TX FIFO threshold, enable TX FIFO threshold interrupt and RX FIFO time-out interrupt */ SPI_EnableFIFO(SPI0, 4, 4); SPI_EnableInt(SPI0, SPI_FIFO_TX_INT_MASK | SPI_FIFO_TIMEOUT_INT_MASK); g_u32TxDataCount = 0; g_u32RxDataCount = 0; NVIC_EnableIRQ(SPI0_IRQn); /* Wait for transfer done */ while(g_u32RxDataCount < TEST_COUNT); /* Print the received data */ printf("Received data:\n"); for(u32DataCount = 0; u32DataCount < TEST_COUNT; u32DataCount++) { printf("%d:\t0x%X\n", u32DataCount, g_au32DestinationData[u32DataCount]); } /* Disable TX FIFO threshold interrupt and RX FIFO time-out interrupt */ SPI_DisableInt(SPI0, SPI_FIFO_TX_INT_MASK | SPI_FIFO_TIMEOUT_INT_MASK); NVIC_DisableIRQ(SPI0_IRQn); printf("The data transfer was done.\n"); printf("\n\nExit SPI driver sample code.\n"); /* Reset SPI0 */ SPI_Close(SPI0); while(1); }
void SPIClass::end(uint8_t _pin) { SPI_Close(spi); }