signed char fReadByteLoop(unsigned int blknum) { bTargetAddress = 0; bTargetDataPtr = 0; while(bTargetDataPtr < TARGET_DATABUFF_LEN) { //Send Read Byte vector and then get a byte from Target SendVector(read_byte_v, 4); // Set the drive here because SendByte() does not SetSDATAStrong(); SendByte(bTargetAddress,7); RunClock(2); // Run two SCLK cycles between writing and reading SetSDATAHiZ(); // Set to HiZ so Target can drive SDATA bTargetDataIN = bReceiveByte(); RunClock(1); SendVector(read_byte_v + 1, 1); // Send the ReadByte Vector End // Test the Byte that was read from the Target against the original // value (already in the 128-Byte array "abTargetDataOUT[]"). If it // matches, then bump the address & pointer,loop-back and continue. // If it does NOT match abort the loop and return and error. //if (bTargetDataIN != abTargetDataOUT[bTargetDataPtr]) if (bTargetDataIN != pSocData[blknum*TARGET_DATABUFF_LEN + bTargetDataPtr]) { #ifdef TX_ON UART_PutCRLF(); UART_CPutString("bTargetDataIN : "); UART_PutHexByte(bTargetDataIN); UART_CPutString(" abTargetDataOUT : "); UART_PutHexByte(pSocData[blknum*TARGET_DATABUFF_LEN + bTargetDataPtr]); #endif return(BLOCK_ERROR); } bTargetDataPtr++; // Increment the address by 2 to accomodate 7-Bit addressing // (puts the 7-bit address into MSBit locations for "SendByte()"). bTargetAddress += 2; } return(PASS); }
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; } } }
// ============================================================================ // fVerifySiliconID() // Returns: // 0 if successful // Si_ID_ERROR if timed out on handshake to the device. // ============================================================================ signed char fVerifySiliconID(void) { SendVector(id_setup_2, num_bits_id_setup_2); fIsError = fDetectHiLoTransition(); if (fIsError) { #ifdef TX_ON UART_PutCRLF(); UART_CPutString("fDetectHiLoTransition Error"); #endif return(SiID_ERROR); } SendVector(wait_and_poll_end, num_bits_wait_and_poll_end); SendVector(tsync_enable, num_bits_tsync_enable); //Send Read ID vector and get Target ID SendVector(read_id_v, 11); // Read-MSB Vector is the first 11-Bits RunClock(2); // Two SCLK cycles between write & read bTargetID[0] = bReceiveByte(); RunClock(1); SendVector(read_id_v+2, 12); // 1+11 bits starting from the 3rd byte RunClock(2); // Read-LSB Command bTargetID[1] = bReceiveByte(); RunClock(1); SendVector(read_id_v+4, 1); // 1 bit starting from the 5th byte //read Revision ID from Accumulator A and Accumulator X //SendVector(read_id_v+5, 11); //11 bits starting from the 6th byte //RunClock(2); //bTargetID[2] = bReceiveByte(); //Read from Acc.X //RunClock(1); //SendVector(read_id_v+7, 12); //1+11 bits starting from the 8th byte // //RunClock(2); //bTargetID[3] = bReceiveByte(); //Read from Acc.A // //RunClock(1); //SendVector(read_id_v+4, 1); //1 bit starting from the 5th byte, SendVector(tsync_disable, num_bits_tsync_disable); #ifdef TX_ON // Print READ-ID UART_PutCRLF(); UART_CPutString("Silicon-ID : "); UART_PutChar(' '); UART_PutHexByte(bTargetID[0]); UART_PutChar(' '); UART_PutHexByte(bTargetID[1]); UART_PutChar(' '); #endif #ifdef LCD_ON LCD_Char_Position(1, 0); LCD_Char_PrintString("ID : "); LCD_Char_PrintInt8(bTargetID[0]); LCD_Char_PutChar(' '); LCD_Char_PrintInt8(bTargetID[1]); LCD_Char_PutChar(' '); #endif if (bTargetID[0] == target_id_v[0] && bTargetID[1] == target_id_v[1]) { return(PASS); } else if (bTargetID[0] == target_id_v2[0] && bTargetID[1] == target_id_v2[1]) { return(PASS); } else { printk("%x %x \n", bTargetID[0], bTargetID[1]); return(SiID_ERROR); } }
int main(){ CyGlobalIntEnable; isrSW_Start(); isr_Timer_Start(); UART_Start(); ADC_Start(); ADC_StartConvert(); CyDelay(50); UART_PutString("nRF Tx\r\n"); NRF_INIT_t tx; tx.channel = NRF_CHANNEL; tx.isTX = true; tx.RF_SETUP_DR = NRF_RF_SETUP_RF_DR_1000; tx.RF_SETUP_PWR = NRF_RF_SETUP_RF_PWR_18; tx.SETUP_RETR_ARC = NRF_SETUP_RETR_ARC_15; tx.SETUP_RETR_ARD = NRF_SETUP_RETR_ARD_1500; /* Start the component before anything else */ nRF_Tx_Start(&tx); /* Test Dynamic Payload */ nRF_Tx_EnableDynamicPayload(NRF_DYNPD_DPL_P0); nRF_Tx_SetRxPayloadSize(NRF_RX_PW_P0, PAYLOAD_SIZE); nRF_Tx_SetRxAddress(ADDR, sizeof(ADDR)); nRF_Tx_SetTxAddress(ADDR, sizeof(ADDR)); Timer_Start(); for(;;){ if(true == isrTimerFlag){ // Stop the Timer just for fun Timer_Stop(); test++; data[0] = pressCount; data[9] = test; ADCoutput = ADC_Read32(); UART_PutString("Resultado de la conversion del ADC: "); UART_PutHexInt((uint16_t)ADCoutput); UART_PutCRLF(); data[1] = (ADCoutput & 0xFF00) >> 8; data[2] = ADCoutput & 0xFF; nRF_Tx_TxTransmit(data, sizeof(data)); isrTimerFlag = false; // Start the Timer again Timer_Start(); } if(isrFlag){ if(nRF_Tx_GetStatus() & NRF_STATUS_RX_DR_MASK){ UART_PutString("Status: "); UART_PutHexByte(nRF_Tx_GetStatus()); UART_PutCRLF(); UART_PutString("RX\r\n"); do{ nRF_Tx_RxPayload(RXdata, sizeof(RXdata)); nRF_Tx_ResetStatusIRQ(NRF_STATUS_RX_DR); nRF_Tx_ReadSingleRegister(NRF_FIFO_STATUS, &status); }while(!(status & NRF_STATUS_TX_FIFO_FULL)); printFlag = true; }else if(nRF_Tx_GetStatus() & NRF_STATUS_TX_DS_MASK){ UART_PutString("Status: "); UART_PutHexByte(nRF_Tx_GetStatus()); UART_PutCRLF(); UART_PutString("TX\r\n"); LED_Write(~LED_Read()); nRF_Tx_ResetStatusIRQ(NRF_STATUS_TX_DS); }else if(nRF_Tx_GetStatus() & NRF_STATUS_MAX_RT_MASK){ UART_PutString("Status: "); UART_PutHexByte(nRF_Tx_GetStatus()); UART_PutCRLF(); UART_PutString("Max RT\r\n"); MAX_Write(~MAX_Read()); nRF_Tx_ResetStatusIRQ(NRF_STATUS_MAX_RT); } isrFlag = false; } 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; } }