本文整理汇总了C++中HAL_I2C_GetState函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_I2C_GetState函数的具体用法?C++ HAL_I2C_GetState怎么用?C++ HAL_I2C_GetState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_I2C_GetState函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFrom
static void readFrom(uint8_t address, uint8_t num) {
// address to read from
aTxBuffer[0] = address;
/*##-2- Start the transmission process #####################################*/
/* While the I2C in reception process, user can transmit data through
"aTxBuffer" buffer */
while(HAL_I2C_Master_Transmit_DMA(&I2cHandle, I2C_ADDRESS << 1, (uint8_t*)aTxBuffer, 1)!= HAL_OK)
{
/* Error_Handler() function is called when Timeout error occurs.
When Acknowledge failure occurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
/*##-3- Wait for the end of the transfer ###################################*/
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it�s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
{
}
// request 6 bytes from device
/*##-4- Put I2C peripheral in reception process ############################*/
while(HAL_I2C_Master_Receive_DMA(&I2cHandle, I2C_ADDRESS << 1, (uint8_t *)aRxBuffer, 6) != HAL_OK)
{
/* Error_Handler() function is called when Timeout error occurs.
When Acknowledge failure occurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
/*##-5- Wait for the end of the transfer ###################################*/
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it�s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
{
}
}
示例2: I2C_EXPBD_Init
/**
* @brief Configures I2C interface
* @retval HAL status
*/
static HAL_StatusTypeDef I2C_EXPBD_Init(void)
{
HAL_StatusTypeDef ret_val = HAL_OK;
if(HAL_I2C_GetState(&I2C_EXPBD_Handle) == HAL_I2C_STATE_RESET)
{
/* I2C_EXPBD peripheral configuration */
#if ((defined (USE_STM32F4XX_NUCLEO)) || (defined (USE_STM32L1XX_NUCLEO)))
I2C_EXPBD_Handle.Init.ClockSpeed = NUCLEO_I2C_EXPBD_SPEED;
I2C_EXPBD_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2;
#endif
#if (defined (USE_STM32L0XX_NUCLEO))
I2C_EXPBD_Handle.Init.Timing = NUCLEO_I2C_EXPBD_TIMING_400KHZ; /* 400KHz */
#endif
I2C_EXPBD_Handle.Init.OwnAddress1 = 0x33;
I2C_EXPBD_Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2C_EXPBD_Handle.Instance = NUCLEO_I2C_EXPBD;
/* Init the I2C */
I2C_EXPBD_MspInit();
ret_val = HAL_I2C_Init(&I2C_EXPBD_Handle);
}
return ret_val;
}
示例3: I2C_SHIELDS_Init
/**
* @brief Configures I2C interface
* @param None
* @retval HAL status
*/
static HAL_StatusTypeDef I2C_SHIELDS_Init(void)
{
HAL_StatusTypeDef ret_val = HAL_OK;
if(HAL_I2C_GetState(&I2C_SHIELDS_Handle) == HAL_I2C_STATE_RESET)
{
/* I2C_SHIELDS peripheral configuration */
// I2C_SHIELDS_Handle.Init.ClockSpeed = NUCLEO_I2C_SHIELDS_SPEED;
// I2C_SHIELDS_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2;
#ifdef STM32F401xE
I2C_SHIELDS_Handle.Init.ClockSpeed = NUCLEO_I2C_SHIELDS_SPEED;
I2C_SHIELDS_Handle.Init.DutyCycle = I2C_DUTYCYCLE_2;
#endif
#ifdef STM32L053xx
I2C_SHIELDS_Handle.Init.Timing = 0x0070D8FF; /*Refer AN4235-Application note Document*/
#endif
I2C_SHIELDS_Handle.Init.OwnAddress1 = 0x33;
I2C_SHIELDS_Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2C_SHIELDS_Handle.Instance = NUCLEO_I2C_SHIELDS;
/* Init the I2C */
I2C_SHIELDS_MspInit();
ret_val = HAL_I2C_Init(&I2C_SHIELDS_Handle);
}
return ret_val;
}
示例4: initMPU
int initMPU(void){
int initOkay = -1;
HAL_I2C_StateTypeDef state;
uint8_t tempByte = 13;
uint8_t buffer[10] = {0,0,0,0,0,0,0,0,0,0};
hnd.Instance = I2C1;
hnd.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hnd.Init.ClockSpeed = 400000;
hnd.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hnd.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hnd.Init.DutyCycle = I2C_DUTYCYCLE_2;
hnd.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
hnd.Init.OwnAddress1 = 0x00;
HAL_I2C_Init(&hnd);
__HAL_I2C_ENABLE(&hnd);
state = HAL_I2C_GetState(&hnd);
if(state == HAL_I2C_STATE_READY){
initOkay = 0;
}
buffer[0]=MPU6050_RA_PWR_MGMT_1;
buffer[1]=0x80;
printf("READ: %u",SCCB_Read(MPU6050_RA_WHO_AM_I));
printf("error: %u",HAL_I2C_GetError(&hnd));
return initOkay;
}
示例5: AP_ReadBuffer
void AP_ReadBuffer(uint8_t RegAddr, uint8_t *aRxBuffer, uint8_t RXBUFFERSIZE)
{
/* -> Lets ask for register's address */
AP_WriteBuffer(&RegAddr, 1);
/* -> Put I2C peripheral in reception process */
while(HAL_I2C_Master_Receive(&AP_I2C_HANDLE, AP_I2C_ADDR, aRxBuffer, (uint16_t)RXBUFFERSIZE, (uint32_t)1000) != HAL_OK)
{
/* Error_Handler() function is called when Timeout error occurs.
* When Acknowledge failure occurs (Slave don't acknowledge it's address)
* Master restarts communication
*/
if (HAL_I2C_GetError(&AP_I2C_HANDLE) != HAL_I2C_ERROR_AF)
{
//DEBUG(3, "In I2C::WriteBuffer -> error");
//Error_Handler(4);
PUTZ_ASSERT(false);
}
}
/* -> Wait for the end of the transfer */
/* Before starting a new communication transfer, you need to check the current
* state of the peripheral; if it’s busy you need to wait for the end of current
* transfer before starting a new one.
* For simplicity reasons, this example is just waiting till the end of the
* transfer, but application may perform other tasks while transfer operation
* is ongoing.
**/
while (HAL_I2C_GetState(&AP_I2C_HANDLE) != HAL_I2C_STATE_READY)
{
}
}
示例6: AP_WriteBuffer
void AP_WriteBuffer(uint8_t *aTxBuffer, uint8_t TXBUFFERSIZE)
{
/* -> Start the transmission process */
/* While the I2C in reception process, user can transmit data through "aTxBuffer" buffer */
while(HAL_I2C_Master_Transmit(&AP_I2C_HANDLE, AP_I2C_ADDR, (uint8_t*)aTxBuffer, (uint16_t)TXBUFFERSIZE, (uint32_t)1000)!= HAL_OK)
{
/*
* Error_Handler() function is called when Timeout error occurs.
* When Acknowledge failure occurs (Slave don't acknowledge it's address)
* Master restarts communication
*/
if (HAL_I2C_GetError(&AP_I2C_HANDLE) != HAL_I2C_ERROR_AF)
{
//DEBUG(3, "In I2C::WriteBuffer -> error");
//Error_Handler(3);
}
}
/* -> Wait for the end of the transfer */
/* Before starting a new communication transfer, you need to check the current
* state of the peripheral; if it’s busy you need to wait for the end of current
* transfer before starting a new one.
* For simplicity reasons, this example is just waiting till the end of the
* transfer, but application may perform other tasks while transfer operation
* is ongoing.
*/
while (HAL_I2C_GetState(&AP_I2C_HANDLE) != HAL_I2C_STATE_READY)
{
}
}
示例7: I2C1_DeInit
/**
* @brief I2C1 Bus Deinitialization
* @retval None
*/
static void I2C1_DeInit(void)
{
if(HAL_I2C_GetState(&heval_I2c1) != HAL_I2C_STATE_RESET)
{
/* DeInit the I2C */
HAL_I2C_DeInit(&heval_I2c1);
I2C1_MspDeInit(&heval_I2c1);
}
}
示例8: getData
//get DATA
static char getData(void)
{
// I2C
uint8_t aRxBuffer[1];
HAL_I2C_Master_Receive_DMA(&hi2c1, (uint16_t)65, (uint8_t *)aRxBuffer, 1);
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)
{
}
return aRxBuffer[0];
}
示例9: i2c_wait_dma_finished
STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) {
// Note: we can't use WFI to idle in this loop because the DMA completion
// interrupt may occur before the WFI. Hence we miss it and have to wait
// until the next sys-tick (up to 1ms).
uint32_t start = HAL_GetTick();
while (HAL_I2C_GetState(i2c) != HAL_I2C_STATE_READY) {
if (HAL_GetTick() - start >= timeout) {
return HAL_TIMEOUT;
}
}
return HAL_OK;
}
示例10: i2c
void i2c (){
I2C_tx_buffer[0]=(uint8_t)MODE;
HAL_I2C_Master_Transmit(&hi2c1, (uint16_t) I2C_ADDRESS, &I2C_tx_buffer[0], 1,100);
//HAL_Delay(10);
HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);
//HAL_I2C_Master_Transmit_IT(&hi2c1, (uint16_t) I2C_ADDRESS, &I2C_tx_buffer[0], 1);
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY); //waiting for the end of current transfer before starting a new one
HAL_I2C_Master_Receive(&hi2c1, (uint16_t) I2C_ADDRESS, &I2C_rx_buffer[0], 1,100);
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY); //waiting for the end of current transfer
for(int i=0;i<10;i++){
HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);
HAL_Delay (500);
}
}
示例11: I2Cx_Init
/**
* @brief Configures I2C interface.
* @param None
* @retval None
*/
static void I2Cx_Init(void)
{
if(HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
{
/* DISCOVERY_I2Cx peripheral configuration */
I2cHandle.Init.ClockSpeed = 10000;
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
I2cHandle.Init.OwnAddress1 = 0x33;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Instance = DISCOVERY_I2Cx;
/* Init the I2C */
I2Cx_MspInit();
HAL_I2C_Init(&I2cHandle);
}
}
示例12: I2Cbar_Init
/**
* @brief Discovery I2Cx Bus initialization
* @param None
* @retval None
*/
void I2Cbar_Init(void)
{
if(HAL_I2C_GetState(&I2CbarHandle) == HAL_I2C_STATE_RESET)
{
I2CbarHandle.Instance = DISCOVERY_I2Cbar;
I2CbarHandle.Init.OwnAddress1 = BAROMETER_I2C_ADDRESS;
I2CbarHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2CbarHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2CbarHandle.Init.OwnAddress2 = 0;
I2CbarHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
I2CbarHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
/* Init the I2C */
I2Cbar_MspInit();
HAL_I2C_Init(&I2CbarHandle);
}
}
示例13: I2Cx_Init
/**
* @brief Eval I2Cx Bus initialization
* @param None
* @retval None
*/
static void I2Cx_Init(void)
{
if(HAL_I2C_GetState(&heval_I2c) == HAL_I2C_STATE_RESET)
{
heval_I2c.Instance = EVAL_I2Cx;
heval_I2c.Init.Timing = EVAL_I2Cx_TIMING;
heval_I2c.Init.OwnAddress1 = 0;
heval_I2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
heval_I2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
heval_I2c.Init.OwnAddress2 = 0;
heval_I2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
heval_I2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
/* Init the I2C */
I2Cx_MspInit(&heval_I2c);
HAL_I2C_Init(&heval_I2c);
}
}
示例14: I2C1_Init
/**
* @brief I2C Bus initialization
* @param None
* @retval None
*/
void I2C1_Init(void)
{
if(HAL_I2C_GetState(&heval_I2c1) == HAL_I2C_STATE_RESET)
{
heval_I2c1.Instance = BSP_I2C1;
heval_I2c1.Init.Timing = I2C1_TIMING;
heval_I2c1.Init.OwnAddress1 = 0;
heval_I2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
heval_I2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
heval_I2c1.Init.OwnAddress2 = 0;
heval_I2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
heval_I2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
heval_I2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
/* Init the I2C */
I2C1_MspInit(&heval_I2c1);
HAL_I2C_Init(&heval_I2c1);
}
}
示例15: I2Cx_Init
/**
* @brief I2Cx Bus initialization.
*/
static void I2Cx_Init(void)
{
if(HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
{
I2cHandle.Instance = DISCOVERY_I2Cx;
I2cHandle.Init.ClockSpeed = BSP_I2C_SPEED;
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
I2cHandle.Init.OwnAddress1 = 0;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2cHandle.Init.OwnAddress2 = 0;
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
/* Init the I2C */
I2Cx_MspInit(&I2cHandle);
HAL_I2C_Init(&I2cHandle);
}
}