XilinxProcessorIPLib/drivers/iic/examples/xiic_tempsensor_example.c
int TempSensorExample(u16 IicDeviceId, u8 TempSensorAddress, u8 *TemperaturePtr)
{
	int Status;
	static int Initialized = FALSE;
	XIic_Config *ConfigPtr;	/* Pointer to configuration data */

	if (!Initialized) {
		Initialized = TRUE;

		/*
		 * Initialize the IIC driver so that it is ready to use.
		 */
		ConfigPtr = XIic_LookupConfig(IicDeviceId);
		if (ConfigPtr == NULL) {
			return XST_FAILURE;
		}

		Status = XIic_CfgInitialize(&Iic, ConfigPtr,
						ConfigPtr->BaseAddress);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}


		/*
		 * Setup handler to process the asynchronous events which occur,
		 * the driver is only interrupt driven such that this must be
		 * done prior to starting the device.
		 */
		XIic_SetRecvHandler(&Iic, (void *)&HandlerInfo, RecvHandler);
		XIic_SetStatusHandler(&Iic, (void *)&HandlerInfo,
						StatusHandler);

		/*
		 * Connect the ISR to the interrupt and enable interrupts.
		 */
		Status = SetupInterruptSystem(&Iic);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}

		/*
		 * Start the IIC driver such that it is ready to send and
		 * receive messages on the IIC interface, set the address
		 * to send to which is the temperature sensor address
		 */
		XIic_Start(&Iic);
		XIic_SetAddress(&Iic, XII_ADDR_TO_SEND_TYPE, TempSensorAddress);
	}

	/*
	 * Clear updated flags such that they can be polled to indicate
	 * when the handler information has changed asynchronously and
	 * initialize the status which will be returned to a default value
	 */
	HandlerInfo.EventStatusUpdated = FALSE;
	HandlerInfo.RecvBytesUpdated = FALSE;
	Status = XST_FAILURE;

	/*
	 * Attempt to receive a byte of data from the temperature sensor
	 * on the IIC interface, ignore the return value since this example is
	 * a single master system such that the IIC bus should not ever be busy
	 */
	(void)XIic_MasterRecv(&Iic, TemperaturePtr, 1);

	/*
	 * The message is being received from the temperature sensor,
	 * wait for it to complete by polling the information that is
	 * updated asynchronously by interrupt processing
	 */
	while(1) {
		if(HandlerInfo.RecvBytesUpdated == TRUE) {
			/*
			 * The device information has been updated for receive
			 * processing,if all bytes received (1), indicate
			 * success
			 */
			if (HandlerInfo.RemainingRecvBytes == 0) {
				Status = XST_SUCCESS;
			}
			break;
		}

		/*
		 * Any event status which occurs indicates there was an error,
		 * so return unsuccessful, for this example there should be no
		 * status events since there is a single master on the bus
		 */
		if (HandlerInfo.EventStatusUpdated == TRUE) {
			break;
		}
	}

	return Status;
}
/*****************************************************************************/
/**
* The function reads the temperature of the IIC temperature sensor on the
* IIC bus. It initializes the IIC device driver and sets it up to communicate
* with the temperature sensor. This function does contain a loop that polls
* for completion of the IIC processing such that it may not return if
* interrupts or the hardware are not working.
*
* @param	IicDeviceId is the XPAR_<IIC_instance>_DEVICE_ID value from
*		xparameters.h for the IIC Device
* @param	TempSensorAddress is the address of the Temperature Sensor device
*		on the IIC bus
* @param	TemperaturePtr is the data byte read from the temperature sensor
*
* @return	XST_SUCCESS to indicate success, else XST_FAILURE to indicate
*		a Failure.
*
* @note		None.
*
*******************************************************************************/
The function reads the temperature of the IIC temperature sensor on the
IIC bus. It initializes the IIC device driver and sets it up to communicate
with the temperature sensor. This function does contain a loop that polls
for completion of the IIC processing such that it may not return if
interrupts or the hardware are not working.
The function reads the temperature of the IIC temperature sensor on the IIC bus . It initializes the IIC device driver and sets it up to communicate with the temperature sensor . This function does contain a loop that polls for completion of the IIC processing such that it may not return if interrupts or the hardware are not working .
int TempSensorExample(u16 IicDeviceId, u8 TempSensorAddress, u8 *TemperaturePtr)
{
	int Status;
	static int Initialized = FALSE;
	XIic_Config *ConfigPtr;	
	if (!Initialized) {
		Initialized = TRUE;
		ConfigPtr = XIic_LookupConfig(IicDeviceId);
		if (ConfigPtr == NULL) {
			return XST_FAILURE;
		}
		Status = XIic_CfgInitialize(&Iic, ConfigPtr,
						ConfigPtr->BaseAddress);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		XIic_SetRecvHandler(&Iic, (void *)&HandlerInfo, RecvHandler);
		XIic_SetStatusHandler(&Iic, (void *)&HandlerInfo,
						StatusHandler);
		Status = SetupInterruptSystem(&Iic);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}
		XIic_Start(&Iic);
		XIic_SetAddress(&Iic, XII_ADDR_TO_SEND_TYPE, TempSensorAddress);
	}
	HandlerInfo.EventStatusUpdated = FALSE;
	HandlerInfo.RecvBytesUpdated = FALSE;
	Status = XST_FAILURE;
	(void)XIic_MasterRecv(&Iic, TemperaturePtr, 1);
	while(1) {
		if(HandlerInfo.RecvBytesUpdated == TRUE) {
			if (HandlerInfo.RemainingRecvBytes == 0) {
				Status = XST_SUCCESS;
			}
			break;
		}
		if (HandlerInfo.EventStatusUpdated == TRUE) {
			break;
		}
	}
	return Status;
}
int TempSensorExample ( u16 IicDeviceId , u8 TempSensorAddress , u8 * TemperaturePtr ) { int Status ; static int Initialized = FALSE ; XIic_Config * ConfigPtr ; if ( ! Initialized ) { Initialized = TRUE ; ConfigPtr = XIic_LookupConfig ( IicDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Status = XIic_CfgInitialize ( & Iic , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIic_SetRecvHandler ( & Iic , ( void * ) & HandlerInfo , RecvHandler ) ; XIic_SetStatusHandler ( & Iic , ( void * ) & HandlerInfo , StatusHandler ) ; Status = SetupInterruptSystem ( & Iic ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIic_Start ( & Iic ) ; XIic_SetAddress ( & Iic , XII_ADDR_TO_SEND_TYPE , TempSensorAddress ) ; } HandlerInfo . EventStatusUpdated = FALSE ; HandlerInfo . RecvBytesUpdated = FALSE ; Status = XST_FAILURE ; ( void ) XIic_MasterRecv ( & Iic , TemperaturePtr , 1 ) ; while ( 1 ) { if ( HandlerInfo . RecvBytesUpdated == TRUE ) { if ( HandlerInfo . RemainingRecvBytes == 0 ) { Status = XST_SUCCESS ; } break ; } if ( HandlerInfo . EventStatusUpdated == TRUE ) { break ; } } return Status ; }
The function reads the temperature of the IIC temperature sensor on the
IIC bus.
The function reads the temperature of the IIC temperature sensor on the IIC bus .
/* Pointer to configuration data */ /*
		 * Initialize the IIC driver so that it is ready to use.
		 */ /*
		 * Setup handler to process the asynchronous events which occur,
		 * the driver is only interrupt driven such that this must be
		 * done prior to starting the device.
		 */ /*
		 * Connect the ISR to the interrupt and enable interrupts.
		 */ /*
		 * Start the IIC driver such that it is ready to send and
		 * receive messages on the IIC interface, set the address
		 * to send to which is the temperature sensor address
		 */ /*
	 * Clear updated flags such that they can be polled to indicate
	 * when the handler information has changed asynchronously and
	 * initialize the status which will be returned to a default value
	 */ /*
	 * Attempt to receive a byte of data from the temperature sensor
	 * on the IIC interface, ignore the return value since this example is
	 * a single master system such that the IIC bus should not ever be busy
	 */ /*
	 * The message is being received from the temperature sensor,
	 * wait for it to complete by polling the information that is
	 * updated asynchronously by interrupt processing
	 */ /*
			 * The device information has been updated for receive
			 * processing,if all bytes received (1), indicate
			 * success
			 */ /*
		 * Any event status which occurs indicates there was an error,
		 * so return unsuccessful, for this example there should be no
		 * status events since there is a single master on the bus
		 */