void lcdc_lead_sleep(void) { SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x28); SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x10); SPI_Stop(); msleep(120); }
void SCA_Init( void ) { SPI_Reset(); SPI_Start(); SPI_WriteByte( MEAS ); SPI_Stop(); }
/*******************************************************************************//** * @implements CC2420_WriteRegister **********************************************************************************/ void CC2420_WriteRegister(CC2420_REGISTER Register,uint16_t Value) { SPI_Start(CC2420Defs.SPI); SPI_TxRx(CC2420Defs.SPI,Register,NULL); SPI_TxRx(CC2420Defs.SPI,(uint8_t)(Value>>8),NULL); SPI_TxRx(CC2420Defs.SPI,(uint8_t)Value,NULL); SPI_Stop(CC2420Defs.SPI); }
/*******************************************************************************//** * @implements CC2420_SendCommandStrobe **********************************************************************************/ uint8_t CC2420_SendCommandStrobe(CC2420_COMMAND_STROBE CommandStrobe) { uint8_t RxByte; SPI_Start(CC2420Defs.SPI); SPI_TxRx(CC2420Defs.SPI,CommandStrobe,&RxByte); SPI_Stop(CC2420Defs.SPI); return RxByte; }
uint16 SPI_GetY( void ) { uint16 result; SPI_Start(); SPI_WriteByte( RDAY ); result = SPI_ReadBits(11); SPI_Stop(); return result; }
uint16 SPI_GetReg(uint8 Cmd,uint8 Length) { uint16 result; SPI_Start(); SPI_WriteByte( Cmd ); result = SPI_ReadBits(Length); SPI_Stop(); return result; }
/*******************************************************************************//** * @implements CC2420_ReadRegister **********************************************************************************/ uint16_t CC2420_ReadRegister(CC2420_REGISTER Register) { uint16_t Result; uint8_t Value; Register |= (1<<CC2420_READ_WRITE_BIT); SPI_Start(CC2420Defs.SPI); SPI_TxRx(CC2420Defs.SPI,Register,NULL); SPI_TxRx(CC2420Defs.SPI,0,&Value); Result = Value<<8; SPI_TxRx(CC2420Defs.SPI,0,&Value); Result |= Value; SPI_Stop(CC2420Defs.SPI); return Result; }
void AppCallBack(uint32 event, void *eventParam) { CYBLE_GATTS_WRITE_REQ_PARAM_T *wrReqParam; switch (event) { case CYBLE_EVT_STACK_ON: /* start advertising */ apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); if(apiResult == CYBLE_ERROR_OK) { #ifdef LED_INDICATION ADV_LED_ON(); #endif /* LED_INDICATION */ } break; case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: sendNotifications = 0; #ifdef ENABLE_SPI_ONLY_WHEN_CONNECTED /* Stop SPI Slave operation */ SPI_Stop(); #endif #ifdef LED_INDICATION /* Indicate disconnect event to user */ DISCON_LED_ON(); CyDelay(3000); #endif /* LED_INDICATION */ /* start advertising */ apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); if(apiResult == CYBLE_ERROR_OK) { #ifdef LED_INDICATION ADV_LED_ON(); #endif /* LED_INDICATION */ } break; case CYBLE_EVT_GATT_CONNECT_IND: #ifdef LED_INDICATION CONNECT_LED_ON(); #endif /* LED_INDICATION */ #ifdef ENABLE_SPI_ONLY_WHEN_CONNECTED /* Start SPI Slave operation */ SPI_Start(); #endif break; /* Client may do Write Value or Write Value without Response. Handle both */ case CYBLE_EVT_GATTS_WRITE_REQ: case CYBLE_EVT_GATTS_WRITE_CMD_REQ: wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam; /* Handling Notification Enable */ if(wrReqParam->handleValPair.attrHandle == CYBLE_SPI_READ_SPI_READ_DATA_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE) { CYBLE_GATT_HANDLE_VALUE_PAIR_T SPINotificationCCDHandle; uint8 SPICCDValue[2]; /* Extract CCCD Notification enable flag */ sendNotifications = wrReqParam->handleValPair.value.val[0]; /* Write the present SPI notification status to the local variable */ SPICCDValue[0] = sendNotifications; SPICCDValue[1] = 0x00; /* Update CCCD handle with notification status data*/ SPINotificationCCDHandle.attrHandle = CYBLE_SPI_READ_SPI_READ_DATA_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE; SPINotificationCCDHandle.value.val = SPICCDValue; SPINotificationCCDHandle.value.len = 2; /* Report data to BLE component for sending data when read by Central device */ CyBle_GattsWriteAttributeValue(&SPINotificationCCDHandle, 0, &cyBle_connHandle, CYBLE_GATT_DB_LOCALLY_INITIATED); } /* Handling Write data from Client */ else if(wrReqParam->handleValPair.attrHandle == CYBLE_SPI_WRITE_SPI_WRITE_DATA_CHAR_HANDLE) { while(SPI_SpiIsBusBusy()) { } SPI_SpiUartClearTxBuffer(); SPI_SpiUartPutArray(wrReqParam->handleValPair.value.val,wrReqParam->handleValPair.value.len); } if (event == CYBLE_EVT_GATTS_WRITE_REQ) { CyBle_GattsWriteRsp(cyBle_connHandle); } break; default: break; } }
void ST7528_1_Start() { SPI_Start(); }
static void lcdc_lead_init(void) {//T38KPS00 CPT3.8"+HX8363A 18BIT RGB INTERFACE, LEAD LCD //msleep(150);//Delay(10*150); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xB9); //Set_EXTC gpio_lcd_lead_emuspi_write_one_data(0xFF); // gpio_lcd_lead_emuspi_write_one_data(0x83); // gpio_lcd_lead_emuspi_write_one_data(0x63); // SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xB1); //Set_POWER gpio_lcd_lead_emuspi_write_one_data(0x81); // gpio_lcd_lead_emuspi_write_one_data(0x30); // gpio_lcd_lead_emuspi_write_one_data(0x03); // gpio_lcd_lead_emuspi_write_one_data(0x34); // gpio_lcd_lead_emuspi_write_one_data(0x01); //02 gpio_lcd_lead_emuspi_write_one_data(0x13); // gpio_lcd_lead_emuspi_write_one_data(0x11); // gpio_lcd_lead_emuspi_write_one_data(0x00); // gpio_lcd_lead_emuspi_write_one_data(0x35); // gpio_lcd_lead_emuspi_write_one_data(0x3E); // gpio_lcd_lead_emuspi_write_one_data(0x1c); // gpio_lcd_lead_emuspi_write_one_data(0x1c); // SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x11); SPI_Stop(); msleep(150);//Delay(10*120); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x3A); //COLMOD //spi_HX8363_Data(0x77); //24bit gpio_lcd_lead_emuspi_write_one_data(0x66); //18bit SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xB3); //Set_RGBIF gpio_lcd_lead_emuspi_write_one_data(0x09); // SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xB4); //Set_CYC gpio_lcd_lead_emuspi_write_one_data(0x00); // gpio_lcd_lead_emuspi_write_one_data(0x03); gpio_lcd_lead_emuspi_write_one_data(0x7E); gpio_lcd_lead_emuspi_write_one_data(0x02); gpio_lcd_lead_emuspi_write_one_data(0x01); gpio_lcd_lead_emuspi_write_one_data(0x12); gpio_lcd_lead_emuspi_write_one_data(0x64); gpio_lcd_lead_emuspi_write_one_data(0x01); gpio_lcd_lead_emuspi_write_one_data(0x60); SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xB6); //Set_VCOM gpio_lcd_lead_emuspi_write_one_data(0x33); // 3c SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xCC); //Set_PANEL gpio_lcd_lead_emuspi_write_one_data(0x09); // SPI_Stop(); msleep(5);//Delay(10*5); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0xE0); //Gamma 2.2 gpio_lcd_lead_emuspi_write_one_data(0x00); // gpio_lcd_lead_emuspi_write_one_data(0x1E); // gpio_lcd_lead_emuspi_write_one_data(0x23); // gpio_lcd_lead_emuspi_write_one_data(0x32); // gpio_lcd_lead_emuspi_write_one_data(0x36); // gpio_lcd_lead_emuspi_write_one_data(0x3F); // gpio_lcd_lead_emuspi_write_one_data(0x08); // gpio_lcd_lead_emuspi_write_one_data(0xCC); // gpio_lcd_lead_emuspi_write_one_data(0x0E); // gpio_lcd_lead_emuspi_write_one_data(0x92); // gpio_lcd_lead_emuspi_write_one_data(0x54); // gpio_lcd_lead_emuspi_write_one_data(0x15); // gpio_lcd_lead_emuspi_write_one_data(0x18); // gpio_lcd_lead_emuspi_write_one_data(0x4F); // gpio_lcd_lead_emuspi_write_one_data(0x19); // gpio_lcd_lead_emuspi_write_one_data(0x00); // gpio_lcd_lead_emuspi_write_one_data(0x1E); // gpio_lcd_lead_emuspi_write_one_data(0x23); // gpio_lcd_lead_emuspi_write_one_data(0x32); // gpio_lcd_lead_emuspi_write_one_data(0x36); // gpio_lcd_lead_emuspi_write_one_data(0x3F); // gpio_lcd_lead_emuspi_write_one_data(0x08); // gpio_lcd_lead_emuspi_write_one_data(0xCC); // gpio_lcd_lead_emuspi_write_one_data(0x0E); // gpio_lcd_lead_emuspi_write_one_data(0x92); // gpio_lcd_lead_emuspi_write_one_data(0x54); // gpio_lcd_lead_emuspi_write_one_data(0x15); // gpio_lcd_lead_emuspi_write_one_data(0x18); // gpio_lcd_lead_emuspi_write_one_data(0x4F); // gpio_lcd_lead_emuspi_write_one_data(0x19); // SPI_Stop(); msleep(5);//Delay(10*5); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x21); //INVON SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x36); //LCD_data_SPI8bit(0x08); gpio_lcd_lead_emuspi_write_one_data(0x03); //GS=1 SPI_Stop(); SPI_Start(); gpio_lcd_lead_emuspi_write_one_index(0x29); SPI_Stop(); printk(KERN_INFO "fxy lcd module TFT Lead init finish\n!"); }
/*******************************************************************************//** * CC2420 thread proc **********************************************************************************/ PROC CC2420_ThreadProc(PARAM Param) { uint16_t Val; uint8_t i,LQI,Byte; int8_t RSSIVal; // request data if(CC2420_OPERATION_IS(PHY_OPERATION_REQUEST_DATA)) { CC2420_STOP_OPERATION(PHY_OPERATION_REQUEST_DATA) // if transmitter is off signal error if(CC2420Defs.State<=CC2420_STATE_IDLE) { SIGNAL_EVENT(PHYLayer_DATA_Confirm(PHY_TRX_OFF)) } // if transmitter is in rx state signal error else if(CC2420Defs.State==CC2420_STATE_RX|| CC2420Defs.State==CC2420_STATE_RX_GOT_SFD|| CC2420Defs.State==CC2420_STATE_RX_REJECT_ALL) { SIGNAL_EVENT(PHYLayer_DATA_Confirm(PHY_RX_ON)) } // everithing is fine, send data else { // if there was tx underflow, then flush tx fifo if(CC2420_SendCommandStrobe(CC2420_SNOP)&(1<<CC2420_STATUS_TX_UNDERFLOW)) { // flush tx buffer CC2420_SendCommandStrobe(CC2420_SFLUSHTX); } // write data to tx fifo SPI_Start(CC2420Defs.SPI); SPI_TxRx(CC2420Defs.SPI,CC2420_TXFIFO,NULL); #ifdef PHY_LAYER_HANDLE_CHECKSUM SPI_TxRx(CC2420Defs.SPI,CC2420Defs.TxLen+2,&Byte); #else SPI_TxRx(CC2420Defs.SPI,CC2420Defs.TxLen,&Byte); #endif for(i=0;i<CC2420Defs.TxLen;++i) { SPI_TxRx(CC2420Defs.SPI,CC2420Defs.TxData[i],NULL); } SPI_Stop(CC2420Defs.SPI); // if there was rx fifo overflow, then flush rx fifo twice if(CC2420_GetRxFIFOOverflow()) { CC2420_SendCommandStrobe(CC2420_SFLUSHRX); CC2420_SendCommandStrobe(CC2420_SFLUSHRX); } // begin transmission CC2420Defs.State = CC2420_STATE_TX; CC2420_SendCommandStrobe(CC2420_STXON); } } // request CCA if(CC2420_OPERATION_IS(PHY_OPERATION_CCA)) { CC2420_STOP_OPERATION(PHY_OPERATION_CCA) // if TRX is off, then return this state if(CC2420Defs.State<=CC2420_STATE_IDLE) { SIGNAL_EVENT(PHYLayer_CCA_Confirm(PHY_TRX_OFF)) } // if tx is on, then return this state else if(CC2420Defs.State==CC2420_STATE_TX|| CC2420Defs.State==CC2420_STATE_TX_GOT_SFD) { SIGNAL_EVENT(PHYLayer_CCA_Confirm(PHY_TX_ON)) } // check CCA and return its state else if(CC2420_GetCCA()) { SIGNAL_EVENT(PHYLayer_CCA_Confirm(PHY_IDLE)) } else { SIGNAL_EVENT(PHYLayer_CCA_Confirm(PHY_BUSY)) } }
int main() { uint8 loop; /* *** Start SPI bus. *** */ SPI_Start(); SPI_SS_Write(1); /* *** Turn off leds at startup. *** */ Led_Red_Write(1); Led_Green_Write(1); Led_Blue_Write(1); /* *** Start serial port. *** */ UART_Start(); UART_PutString("\nPSoC RFM69 Test... PSoC 5LP...\n"); /* *** Blink Red Led two times before starting RFM69 module. * ***/ Led_Red_Write(0); CyDelay(250); Led_Red_Write(1); CyDelay(250); Led_Red_Write(0); CyDelay(250); Led_Red_Write(1); CyDelay(250); /* *** Start RFM69 module. Configure it. If the module is not found, program gets locked. And red led gets turned on. If can find RFM module, then turn on green led. *** */ UART_PutString("Looking for RFM69 module... "); if (RFM69_Start() != 1) { UART_PutString("FAILED\n\n"); Led_Red_Write(0); while (1) {}; } else { UART_PutString("OK\n\n"); Led_Green_Write(1); } /* If testing with interrupts. But disabled until entering RX mode. */ #ifdef TEST_USING_INTERRUPTS RFM_isr_StartEx(RFM69_IsrHandler); #endif /* Start SysTick. When compiled for "MASTER" this is used to control timeout while in reception state. */ CySysTickStart(); // interrupt every 1ms. /* Find unused callback slot. */ for (loop = 0; loop < CY_SYS_SYST_NUM_OF_CALLBACKS; ++loop) { if (CySysTickGetCallback(loop) == NULL) { /* Set callback */ CySysTickSetCallback(loop, SysTickIsrHandler); break; } } /* ----------------------------------------- */ /* Configuration depending on node type. */ #ifdef COMPILE_FOR_MASTER Config_ForMaster(); #endif #if defined COMPILE_FOR_SLAVE_1 || defined COMPILE_FOR_SLAVE_2 Config_ForSlave(); #endif /* ----------------------------------------- */ /* Uncomment next line and adjust params if you want to change bitrate at runtime. */ RFM69_SetBitrateCls(BITRATE_MSB_9600, BITRATE_LSB_9600); /* If testing using encryption, change encryption mode and key at runtime. */ #ifdef TEST_WITH_ENCRYPTION RFM69_Encryption(1, encryptionkey); #endif CyGlobalIntEnable; /* Enable global interrupts. */ for(;;) { /* ----------------------------------------- */ /* Call main loop depending on node type. */ #ifdef COMPILE_FOR_MASTER Loop_Master(); #endif #if defined COMPILE_FOR_SLAVE_1 || defined COMPILE_FOR_SLAVE_2 Loop_Slave(); #endif /* ----------------------------------------- */ } }
int main() { uint8 data; uint8 payload; char OutputString[8]; uint8 status; CyGlobalIntEnable; SPI_Start(); UART_Start(); UART_UartPutString("\n"); UART_UartPutString("Writing registers... \n"); // reflect TX_DS and MAX_RT interrupts as IRQ active low, enable 2-byte CRC, power-up, TX mode NRF24L01_WriteReg(NRF24L01_00_CONFIG, 0x4E); //01001110 // enable auto acknowledgement pipe 0 NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x01); //00000001 // 5 byte address width NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); //00000011 // 1 byte of payload on pipe 0 NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, 0x01); //00000001 UART_UartPutString("Reading registers... \n"); sprintf(OutputString, "Config: %x \n", NRF24L01_ReadReg(NRF24L01_00_CONFIG)); UART_UartPutString(OutputString); sprintf(OutputString, "EN_AA: %x \n", NRF24L01_ReadReg(NRF24L01_01_EN_AA)); UART_UartPutString(OutputString); sprintf(OutputString, "Setup_AW: %x \n", NRF24L01_ReadReg(NRF24L01_03_SETUP_AW)); UART_UartPutString(OutputString); sprintf(OutputString, "RX_PW_P0: %x \n", NRF24L01_ReadReg(NRF24L01_11_RX_PW_P0)); UART_UartPutString(OutputString); UART_UartPutString("\n"); for(;;) { //reading input LED_Write(!SW_Read()); payload = !SW_Read(); //sending data into TX FIFO NRF24L01_WritePayload(&payload, 1); //transmitting data CE_Write(1); CyDelayUs(10); CE_Write(0); //waiting for interrupt while (IRQ_Read()) ; //checking interrupt type (0x2E = TX_DS, RX FIFO empty) data = NRF24L01_ReadReg(NRF24L01_07_STATUS); sprintf(OutputString, "%x: ", data); UART_UartPutString(OutputString); // TX_DS = 0x20 MAX_RT = 0x10 if ((data & 0x20) || (data & 0x10)){ if ((data & 0x20)) UART_UartPutString("Data sent!\n"); if (data & 0x10) UART_UartPutString("Max RT achieved!\n"); } else { UART_UartPutString("Wrong interrupt?\n"); } //clearing status register NRF24L01_WriteReg(NRF24L01_07_STATUS, (1 << NRF24L01_07_RX_DR) | (1 << NRF24L01_07_TX_DS) | (1 << NRF24L01_07_MAX_RT)); //delay for debugging purposes CyDelay(750); } }
int main(){ CyGlobalIntEnable; SPI_Start(); UART_Start(); isrIRQ_Start(); isrBTN_Start(); ADC_Start(); CyDelay(100); UART_PutString("Test TX and Rx Payload\r\n"); NRF_INIT_t tx; tx.channel = CHANNEL; tx.isTX = true; tx.RF_SETUP_DR = NRF_RF_SETUP_RF_DR_1000; tx.RF_SETUP_PWR = 0; tx.SETUP_RETR_ARC = NRF_SETUP_RETR_ARC_15; tx.SETUP_RETR_ARD = NRF_SETUP_RETR_ARD_1500; // Test Rx Payload NRF_WriteSingleRegister(NRF_DYNPD, 0x01u); NRF_WriteSingleRegister(NRF_FEATURE, 0x06u); NRF_SetRxPayloadSize(NRF_RX_PW_P0, PAYLOAD_SIZE); // NRF_SetRxAddress(ADDR, sizeof(ADDR)); NRF_SetTxAddress(ADDR, sizeof(ADDR)); NRF_Init(&tx); NRF_TxTransmit(data, sizeof(data)); CyDelay(4000); NRF_GetRetransmissionsCount(&test); UART_PutHexByte(test); UART_PutCRLF(); for(;;){ /* if(pressCount){ if(3 == pressCount) pressCount = 0; ADCoutput = ADC_Read32(); data[1] = (ADCoutput & 0xFF00) >> 8; data[2] = ADCoutput & 0xFF; data[6] = pressCount; NRF_TxTransmit(data, sizeof(data)); } */ count++; if(12 == count){ if(250 == pressCount){ pressCount = 0; } if(250 == test){ test = 0; } count = 0; test++; data[9] = test; data[0] = pressCount; ADCoutput = ADC_Read32(); data[1] = (ADCoutput & 0xFF00) >> 8; data[2] = ADCoutput & 0xFF; NRF_TxTransmit(data, sizeof(data)); } CyDelay(20); NRF_GetLostPackets(&test); if(0x0F == test){ NRF_ResetStatusIRQ(NRF_STATUS_MAX_RT); } UART_PutHexByte(test); UART_PutCRLF(); if(isrFlag){ isrFlag = false; if(NRF_GetStatus() & 0x40u){ /* RX_DR: Data Received */ do{ NRF_RxPayload(RXdata, sizeof(RXdata)); NRF_ResetStatusIRQ(NRF_STATUS_RX_DR); NRF_ReadSingleRegister(NRF_FIFO_STATUS, &status); }while(!(status & 0x01)); printFlag = true; }else if(NRF_GetStatus() & 0x60u){ /* TX_DS: Data Sent */ LED_Write(~LED_Read()); NRF_ResetStatusIRQ(NRF_STATUS_TX_DS); }else if(NRF_GetStatus() & 0x10u){ /* MAX_RT: Retry Timeout */ MAX_Write(~MAX_Read()); NRF_ResetStatusIRQ(NRF_STATUS_MAX_RT); } } if(printFlag){ UART_PutHexByte(RXdata[0]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[1]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[2]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[3]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[4]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[5]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[6]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[7]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[8]); UART_PutString("\r\n"); UART_PutHexByte(RXdata[9]); UART_PutString("\r\n"); printFlag = false; } } }