STM32F207 I2C test failing

流过昼夜 提交于 2019-12-06 01:25:00

Sorry for the delay in mentioning this, but I have successfully solved this problem by using the STM32 CPAL library available from ST. I have tested this library with the onboard accelerometer by reading the 'WHO_AM_I' register in the accelerometer. The code for this is:

#include "cpal_i2c.h"

int main()
{
    // Configuration
    CPAL_TransferTypeDef RxStruct;
    uint8_t RxBuf;
    RxStruct.pbBuffer = &RxBuf;
    RxStruct.wAddr1 = 0x39;
    // Initialization
    CPAL_I2C_StructInit(&I2C1_DevStructure);
    I2C1_DevStructure.CPAL_Mode = CPAL_MODE_MASTER;
    I2C1_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
    I2C1_DevStructure.pCPAL_I2C_Struct->I2C_ClockSpeed = 100000;
    I2C1_DevStructure.pCPAL_TransferRx = &RxStruct;
    I2C1_DevStructure.pCPAL_TransferTx = pNULL;
    CPAL_I2C_Init(&I2C1_DevStructure);
    // Communication
    RxStruct.wNumData = 1;
    RxStruct.wAddr2 = 0x0F;
    if(CPAL_I2C_Read(&I2C1_DevStructure) != CPAL_PASS)
    {
        // Error
    }
    while(I2C1_DevStructure.CPAL_State != CPAL_STATE_READY);
    while(1);
    return 0;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!