82 #include <stm32f4xx.h>
87 #define TIMEOUT_MAX 0x3000
134 GPIO_InitStruct.
GPIO_PuPd = GPIO_PuPd_NOPULL;
145 I2C_InitStruct[0].
I2C_Ack = I2C_Ack_Enable;
151 I2C_InitStruct[1].
I2C_Ack = I2C_Ack_Enable;
227 uint8_t twoByte, uint8_t *pdata, uint16_t count) {
233 if (--timeout == 0) {
241 if (--timeout == 0) {
249 if (--timeout == 0) {
257 while (!
I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING )) {
258 if (--timeout == 0) {
266 if (--timeout == 0) {
273 while (!
I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING )) {
274 if (--timeout == 0) {
280 for (i = 0; i < count; i++) {
284 if (--timeout == 0) {
313 uint8_t twoByte, uint8_t *pdata, uint16_t count) {
319 if (--timeout == 0) {
327 if (--timeout == 0) {
335 if (--timeout == 0) {
343 while (!
I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING )) {
344 if (--timeout == 0) {
352 if (--timeout == 0) {
359 while (!
I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING )) {
360 if (--timeout == 0) {
369 if (--timeout == 0) {
377 if (--timeout == 0) {
382 for (i = 0; i < count - 1; i++) {
385 if (--timeout == 0) {
398 if (--timeout == 0) {
405 while (I2Cx->CR1 & I2C_CR1_STOP ) {
406 if (--timeout == 0) {
static ERROR_CODES CARME_I2C_Timeout(I2C_TypeDef *I2Cx)
Restart the I2C periph if a timeout has occurred.
uint8_t ERROR_CODES
Error variable.
void I2C_Send7bitAddress(I2C_TypeDef *I2Cx, uint8_t Address, uint8_t I2C_Direction)
Transmits the address byte to select the slave device.
GPIOOType_TypeDef GPIO_OType
#define I2C_EVENT_MASTER_MODE_SELECT
Communication start.
ErrorStatus I2C_CheckEvent(I2C_TypeDef *I2Cx, uint32_t I2C_EVENT)
Checks whether the last I2Cx Event is equal to the one passed as parameter.
void I2C_Init(I2C_TypeDef *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
#define CARME_I2C_ADDR_BOARD
GPIOSpeed_TypeDef GPIO_Speed
GPIOPuPd_TypeDef GPIO_PuPd
void CARME_GPIO_Init(CARME_Port_Pin_t *pPortPinAssociation, GPIO_InitTypeDef *pGPIO_InitStruct, uint8_t size)
Initialize GPIO ports with a CARME_Port_Pin_t table.
void I2C_GenerateSTOP(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication STOP condition.
void GPIO_StructInit(GPIO_InitTypeDef *GPIO_InitStruct)
Fills each GPIO_InitStruct member with its default value.
ERROR_CODES CARME_I2C_Read(I2C_TypeDef *I2Cx, uint8_t addr, uint16_t reg, uint8_t twoByte, uint8_t *pdata, uint16_t count)
Read data from an I2C slave device on a specific register address.
#define CARME_I2C_ADDR_AUDIO
CARME port and pin association structure.
void I2C_DeInit(I2C_TypeDef *I2Cx)
Deinitialize the I2Cx peripheral registers to their default reset values.
#define CARME_ERROR_I2C_TIMEOUT
void I2C_Cmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C peripheral.
FlagStatus I2C_GetFlagStatus(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Checks whether the specified I2C flag is set or not.
static CARME_Port_Pin_t CARME_I2C_Port_Pin[]
I2C Port and Pin association.
GPIO Init structure definition.
void I2C_SoftwareResetCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C software reset.
void CARME_I2C_Init(I2C_TypeDef *I2Cx)
I2C initialization.
static I2C_InitTypeDef I2C_InitStruct[2]
I2C init structures to reinitialize the interface, if it is crashed.
void I2C_AcknowledgeConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C acknowledge feature.
void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Enables or disables the Low Speed APB (APB1) peripheral clock.
void I2C_ClearFlag(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
Clears the I2Cx's pending flags.
#define I2C_EVENT_MASTER_BYTE_RECEIVED
Communication events.
ERROR_CODES CARME_I2C_Write(I2C_TypeDef *I2Cx, uint8_t addr, uint16_t reg, uint8_t twoByte, uint8_t *pdata, uint16_t count)
Write data to an I2C slave device on a specific register address.
uint8_t I2C_ReceiveData(I2C_TypeDef *I2Cx)
Returns the most recent received data by the I2Cx peripheral.
void I2C_StructInit(I2C_InitTypeDef *I2C_InitStruct)
Fills each I2C_InitStruct member with its default value.
I2C Init structure definition.
#define I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED
Address Acknowledge.
static void CARME_I2C_Settings(I2C_TypeDef *I2Cx)
I2C interface initialization.
void I2C_SendData(I2C_TypeDef *I2Cx, uint8_t Data)
Sends a data byte through the I2Cx peripheral.
void I2C_GenerateSTART(I2C_TypeDef *I2Cx, FunctionalState NewState)
Generates I2Cx communication START condition.
I2C board support package for the CARME module.