/*** TMP3_ReadIIC ** ** Parameters: ** InstancePtr - PmodTMP3 object to initialize ** reg - Register to read from ** Data - Pointer to recieve buffer ** nData - Number of data values to read ** ** Return Value: ** none ** ** Errors: ** none ** ** Description: ** Reads nData data bytes from register reg ** */ void TMP3_ReadIIC(PmodTMP3* InstancePtr, u8 reg, u8 *Data, int nData) { int Status; Status = XIic_Start(&InstancePtr->TMP3Iic); if (Status != XST_SUCCESS) { return; } if (InstancePtr->currentRegister!=reg){ //XIic_MasterSend(&InstancePtr->TMP3Iic, ®, 1); XIic_Send(InstancePtr->TMP3Iic.BaseAddress, InstancePtr->chipAddr, ®, 1, XII_REPEATED_START_OPTION); InstancePtr->currentRegister=reg; }//else{ //XIic_MasterRecv(&InstancePtr->TMP3Iic, Data, nData); //} XIic_Recv(InstancePtr->TMP3Iic.BaseAddress, InstancePtr->chipAddr, Data, nData, XIIC_STOP); //XIic_MasterSend(&InstancePtr->TMP3Iic, ®, 2); //InstancePtr->recvbytes=nData+1; //InstancePtr->recv=Data; //XIic_MasterRecv(&InstancePtr->TMP3Iic, Data, nData); Status = XIic_Stop(&InstancePtr->TMP3Iic); if (Status != XST_SUCCESS) { return; } }
/** * * The function reads the temperature of the IIC temperature sensor on the * IIC bus using the low-level driver. * * @param IicBaseAddress is the base address of the device. * @param TempSensorAddress is the address of the Temperature Sensor device * on the IIC bus. * @param TemperaturePtr is the databyte read from the temperature sensor. * * @return The number of bytes read from the temperature sensor, normally one * byte if successful. * * @note None. * ****************************************************************************/ int LowLevelTempSensorExample(u32 IicBaseAddress, u8 TempSensorAddress, u8 *TemperaturePtr) { int ByteCount; ByteCount = XIic_Recv(IicBaseAddress, TempSensorAddress, TemperaturePtr, 1, XIIC_STOP); return ByteCount; }
int read_i2c_reg(u32 i2c_driver, u8 i2c_addr, u8 regaddr, u8* prdvalue) { // uses low-level driver to read from an i2c register // returns 1 if read successful, otherwise 0 u8 wrbuf[4]; unsigned int xcount; wrbuf[0] = regaddr; xcount = XIic_Send(i2c_driver, i2c_addr, &wrbuf[0], 1, XIIC_STOP); if (xcount != 1) { xil_printf("?I2C Send Error on Register Read\r\n"); return 0; } xcount = XIic_Recv(i2c_driver, i2c_addr, &wrbuf[0], 1, XIIC_STOP); *prdvalue = wrbuf[0]; if (xcount == 1) return 1; else { xil_printf("?I2C Recv Error on Register Read\r\n"); return 0; } }
/****************************************************************************** * Function to read one byte (8-bits) from the register space of audio controller. * * @param u8RegAddr is the LSB part of the register address (0x40xx). * @param u8RxData is the returned value * * @return XST_SUCCESS if the desired number of bytes have been read from the controller * XST_FAILURE otherwise *****************************************************************************/ XStatus fnAudioReadFromReg(u8 u8RegAddr, u8 *u8RxData) { u8 u8TxData[2]; u8 u8BytesSent, u8BytesReceived; u8TxData[0] = 0x40; u8TxData[1] = u8RegAddr; u8BytesSent = XIic_Send(XPAR_IIC_0_BASEADDR, IIC_SLAVE_ADDR, u8TxData, 2, XIIC_STOP); //check if all the bytes where sent if (u8BytesSent != 2) { return XST_FAILURE; } u8BytesReceived = XIic_Recv(XPAR_IIC_0_BASEADDR, IIC_SLAVE_ADDR, u8RxData, 1, XIIC_STOP); //check if there are missing bytes if (u8BytesReceived != 1) { return XST_FAILURE; } return XST_SUCCESS; }
/****************************************************************************** * Configures audio codes's internal PLL. With MCLK = 12.288 MHz it configures the * PLL for a VCO frequency = 49.152 MHz. * * @param none. * * @return XST_SUCCESS if PLL is locked *****************************************************************************/ XStatus fnAudioPllConfig() { u8 u8TxData[8], u8RxData[6]; int Status; Status = fnAudioWriteToReg(R0_CLOCK_CONTROL, 0x0E); if (Status == XST_FAILURE) { if (Demo.u8Verbose) { xil_printf("\r\nError: could not write R0_CLOCK_CONTROL (0x0E)"); } return XST_FAILURE; } // Write 6 bytes to R1 // For setting the PLL with a MCLK = 12.288 MHz the datasheet suggests the // following configuration 0xXXXXXX2001 u8TxData[0] = 0x40; u8TxData[1] = 0x02; u8TxData[2] = 0x00; // byte 1 u8TxData[3] = 0x7D; // byte 2 u8TxData[4] = 0x00; // byte 3 u8TxData[5] = 0x0C; // byte 4 u8TxData[6] = 0x20; // byte 5 u8TxData[7] = 0x01; // byte 6 Status = XIic_Send(XPAR_IIC_0_BASEADDR, IIC_SLAVE_ADDR, u8TxData, 8, XIIC_STOP); if (Status != 8) { if (Demo.u8Verbose) { xil_printf("\r\nError: could not send data to R1_PLL_CONTROL (0xXXXXXX2001)"); } return XST_FAILURE; } // Poll PLL Lock bit u8TxData[0] = 0x40; u8TxData[1] = 0x02; //Wait for the PLL to lock do { XIic_Send(XPAR_IIC_0_BASEADDR, IIC_SLAVE_ADDR, u8TxData, 2, XIIC_STOP); XIic_Recv(XPAR_IIC_0_BASEADDR, IIC_SLAVE_ADDR, u8RxData, 6, XIIC_STOP); if(Demo.u8Verbose) { xil_printf("\nAudio PLL R1 = 0x%x%x%x%x%x%x", u8RxData[0], u8RxData[1], u8RxData[2], u8RxData[3], u8RxData[4], u8RxData[5]); } } while((u8RxData[5] & 0x02) == 0); //Set COREN Status = fnAudioWriteToReg(R0_CLOCK_CONTROL, 0x0F); if (Status == XST_FAILURE) { if (Demo.u8Verbose) { xil_printf("\r\nError: could not write R0_CLOCK_CONTROL (0x0F)"); } return XST_FAILURE; } return XST_SUCCESS; }