/* Initialize I/Os in Output Mode */
GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN), GPIO_MODE_OUT_PP_LOW_FAST);
/* Optional: put here as example only */
I2C_DeInit();
/* Initialize the I2C */
I2C_Init(200000, 0x0102, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_10BIT, 16);
/* All LEDs are ON per default */
GPIO_WriteHigh(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN));
/*----- Transmission Phase -----*/
/* Send START condition */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
/* Send Header to Slave for write */
I2C_SendData(HEADER_ADDRESS_Write);
/* Test on EV9 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_HEADER_ACKED));
/* Send slave Address for write */
I2C_Send7bitAddress(0x30, I2C_DIRECTION_TX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
/* Send data */
Tx_Idx = 0;
while (Tx_Idx < 4)
{
/* Send data */
I2C_SendData(tmpbuff[Tx_Idx++]);
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}
/* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);
/* Toggle all LEDs when I2C communication is terminated */
while (1)
{
GPIO_WriteReverse(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN));
Delay((u16)60000);
}
}
/**
* @brief Reports the name of the source file and the source line number where
* the assert error has occurred.
* User can add his own implementation to report the file name and line number.
* ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line)
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
*/
#ifdef FULL_ASSERT
void assert_failed(u8 *file, u16 line)
#else
void assert_failed(void)
#endif
{
/* Add your own code to manage an assert error */
/* Infinite loop */
while (1)
{
}
}
/**
* @}
*/
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/