unsigned char* read(void) { askAboutSending(); unsigned char *readBuffer = NULL; int statusRxFifoFilling = 0; int howManyRead = 0; statusRxFifoFilling = USIC_GetRxFIFOFillingLevel(UART001_0_USIC_CH); if(((UART001_GetFlagStatus(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG)) == UART001_SET)) { statusRxFifoFilling = USIC_GetRxFIFOFillingLevel(UART001_0_USIC_CH); if(statusRxFifoFilling != 0) { readBuffer = (unsigned char *)malloc((sizeof(unsigned char)*statusRxFifoFilling) + 1); howManyRead = UART001_ReadDataBytes(&UART001_Handle0, readBuffer, statusRxFifoFilling); readBuffer[statusRxFifoFilling] = '\0'; } UART001_ClearFlag(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG); while(!USIC_ubIsRxFIFOempty(UART001_0_USIC_CH)) { USIC_FlushRxFIFO(UART001_0_USIC_CH); } } stopAskingAboutSending(); return readBuffer; }
void read(void) { emptyReadData(); if(((UART001_GetFlagStatus(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG)) == UART001_SET)) { IO004_TogglePin(IO004_Handle1); statusRxFifoFilling = USIC_GetRxFIFOFillingLevel(UART001_0_USIC_CH); howManyRead = UART001_ReadDataBytes(&UART001_Handle0, readData, statusRxFifoFilling); if(strcmp(readData, "LSM9DS1") == 0) { chosenSensor = 1; } else if(strcmp(readData, "TEMP_SENSOR") == 0) { chosenSensor = 2; } UART001_ClearFlag(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG); while(!USIC_ubIsRxFIFOempty(UART001_0_USIC_CH)) { USIC_FlushRxFIFO(UART001_0_USIC_CH); } copyData(); stopAskingAboutSending(); } }
uint32_t UART001_ReadDataMultiple\ (const UART001_HandleType* Handle,uint16_t* DataPtr,uint32_t Count) { uint32_t ReadCount = 0x00U; USIC_CH_TypeDef* UartRegs = Handle->UartRegs; DBG002_FUNCTION_ENTRY(APP_GID,UART001_FUN_ENTRY); /* <<<DD_UART001_API_1>>>*/ while(! USIC_ubIsRxFIFOempty(UartRegs) && Count) { *DataPtr = (uint16_t)UartRegs->OUTR; Count--; ReadCount++; DataPtr++; } DBG002_FUNCTION_EXIT(APP_GID,UART001_FUN_EXIT); return ReadCount; }
/* This function reads out the content of the USIC receive FIFO Buffer. * Returns true in case FIFO is not empty.else otherwise. * */ bool I2C001_ReadData(const I2C001Handle_type* I2CHandle, uint16_t* buffer) { bool Result = (bool)FALSE; USIC_CH_TypeDef* I2CRegs = I2CHandle->I2CRegs; /* <<<DD_I2C001_API_4>>>*/ if(USIC_ubIsRxFIFOempty(I2CRegs)) { Result = (bool)FALSE; } else { *buffer = (uint8_t)I2CRegs->OUTR; Result = (bool)TRUE; } return Result; }
/******************************************************************************* * @brief When receive FIFO buffer is enabled, this function reads out the * content of the USIC receive FIFO Buffer. Returns true in case FIFO is not * empty else otherwise. * But when receive FIFO buffer is disabled, this function reads out the * content of the USIC receive standard Buffer. * * @param[in] Handle of type I2C003_HandleType * @param[out] Buffer reference of type uint16_t * * @return bool<BR> * TRUE : if FIFO is not empty & data is read.<BR> * FALSE : if FIFO is empty.<BR> * * <b>Reentrant: NO </b><BR> ******************************************************************************/ bool I2C003_ReadData(const I2C003_HandleType* Handle, uint8_t* Buffer) { bool Result = (bool)FALSE; USIC_CH_TypeDef* I2CRegs; I2CRegs = Handle->I2CRegs; if(Handle->RxFifoEn) { if (!USIC_ubIsRxFIFOempty(I2CRegs)) { *Buffer = (uint8_t)I2CRegs->OUTR; Result = (bool)TRUE; } }else { *Buffer = (uint8_t)I2CRegs->RBUF; Result = (bool)TRUE; } return Result; }
void readHumidTimerHandler(void *T) { I2C001_DataType data1; data1.Data1.TDF_Type = I2C_TDF_MRStart; data1.Data1.Data = ((HTDU21D_ADDRESS << 1) | I2C_READ); I2C001_WriteData(&I2C001_Handle1,&data1); delay11(DELAY); if(I2C001_GetFlagStatus(&I2C001_Handle1,I2C001_FLAG_NACK_RECEIVED) == I2C001_SET) { I2C001_ClearFlag(&I2C001_Handle1,I2C001_FLAG_NACK_RECEIVED); errorCounter++; } else { uint8_t msb = 0x00; uint8_t lsb = 0x00; uint8_t checksum = 0x00; USIC_CH_TypeDef* I2CRegs = I2C001_Handle1.I2CRegs; I2C001_DataType data2; data2.Data1.TDF_Type = I2C_TDF_MRxAck0; data2.Data1.Data = ubyteFF; I2C001_WriteData(&I2C001_Handle1,&data2); delay11(DELAY); if(!USIC_ubIsRxFIFOempty(I2CRegs)) { msb = (uint8_t)I2CRegs->OUTR; //Result = (bool)TRUE; } I2C001_DataType data3; data3.Data1.TDF_Type = I2C_TDF_MRxAck0; data3.Data1.Data = ubyteFF; I2C001_WriteData(&I2C001_Handle1,&data3); delay11(DELAY); if(!USIC_ubIsRxFIFOempty(I2CRegs)) { lsb = (uint8_t)I2CRegs->OUTR; //Result = (bool)TRUE; } I2C001_DataType data4; data4.Data1.TDF_Type = I2C_TDF_MRxAck1; data4.Data1.Data = ubyteFF; I2C001_WriteData(&I2C001_Handle1,&data4); delay11(DELAY); I2C001_DataType data5; data5.Data1.TDF_Type = I2C_TDF_MStop; data5.Data1.Data = ubyteFF; I2C001_WriteData(&I2C001_Handle1,&data5); delay11(DELAY); int d = USIC_GetRxFIFOFillingLevel(I2CRegs); // Read receive buffer, put the data in DataReceive1 if(!USIC_ubIsRxFIFOempty(I2CRegs)) { checksum = (uint8_t)I2CRegs->OUTR; //Result = (bool)TRUE; } unsigned int rawHumid = ((unsigned int) msb << 8) | (unsigned int) lsb; if(check_crc(rawHumid, checksum) != 0) { wrong_checksum = 1; } rawHumid &= 0xFFFC; //Zero out the status bits but keep them in place //Given the raw temperature data, calculate the actual temperature float tempRH = rawHumid / (float)65536; //2^16 = 65536 rh = -6 + (125 * tempRH); //From page 14 readHumid = 1; } }