Hello Dialog,
I am trying to communicate DA14531 MOD and MCP3422 (Analog to Digital Converter). But, I am not able to identify whether I2C connection is established or not. Can you please help me with this issue.
// *user_code_start.*//
const i2c_cfg_t * cfg;
//________Setup Master______//
i2c_restart_t restart = I2C_RESTART_ENABLE; // Restart condition enabled
i2c_addressing_t addr_mode = i2c_addressing_7b;// 7位寻址
uint16_t target_addr = 0x68;//目标/从地址(1101000用于MCP3422)
// ________主接收缓冲区______ //
UINT8_T *数据;//存储数据的缓冲区的地址
uint16_t len = 1;//数据缓冲区的长度
i2c_abort_t * abrt_code;//(如果不是null,操作的状态) - i2c_abort_none
UINT32_T标志;//
// *user_code_end.*//
// *main.c caid_start.*//
system_init();
I2C_INIT(CFG);
i2c_setup_master(重新启动,addr_mode,target_addr);
UInt16_t bytesreceive = i2c_master_receive_buffer_sync((uint8_t *)和数据,len,abrt_code,i2c_f_add_stop);
printf_string(UART, "\n\rData bytes received = "); // Debug output
printf_byte(UART,BYTESRECERED);
printf_string(UART,“\ n \ rdata收到=”);//调试输出
printf_byte(UART, *data);
uint16_t bytesSent = i2c_master_transmit_buffer_sync((uint8_t*) data, len, abrt_code, I2C_F_ADD_STOP);
printf_string(UART, "\n\rData bytes sent = "); // Debug output
printf_byte(UART,BYTESSENT);
printf_string(UART,“\ n \ rdata sent =”);//调试输出
printf_byte(UART, *data);
// *main.c CODE_END*//
1.在“i2c_master_receive_buffer_sync((uint8_t*)&data, len, abrt_code, I2C_F_ADD_STOP);“功能我没有定义任何值”abrt_code.“。没关系吗?如果不是我可以传递的价值?
2. In the above-mentioned function, I have passed "I2C_F_ADD_STOP“作为国旗论证。没关系吗?
3. I am getting same output (as mentioned below) in my Tera Term in both cases (whether I connected SDA, SCL, VCC and GND pins from MCP3422 to DA14531 or not). I am not able to understand my code is working or not. Please let me know if I was missing anything?
收到的数据字节= 00
Data received = 50
数据字节发送= 01
数据发送= 50
I hope you will respond to this very soon.
先感谢您
D.ravikiran.
Hi RAVIKIRAN,
这 ”abrt_code.“ 在 ”i2c_master_receive_buffer_sync((uint8_t*)&data, len, abrt_code, I2C_F_ADD_STOP);" could be used to check the operation status when it's NULL. Please check this value to get the status.
You passed "I2C_F_ADD_STOP“在功能中没有问题,这只是在交易结束时停止条件。
您打印的值是预期的,数据发送的数据应与收到的数据相同,并且已发送的字节是1,这是在函数中传递的长度。如上所述,需要检查ABRT_CODE的状态。
Br,
pw_dialog.
Thank you for your response,
根据您的答案,我已经检查了abrt_code状态,我也已经修改了一些其他错误和状态检查。
// *USER_Variables&Prototype_START *//
静态void set_dev_addr(uint8_t);
int i2cm_write(uint8_t, uint8_t const * const, uint8_t, bool);
int i2cm_read(uint8_t, uint8_t * const, uint8_t, bool);
静态int read(uint8_t,uint8_t * const,uint8_t);
static const i2c_cfg_t i2c_cfg = {
.clock_cfg.ss_hcnt = i2c_ss_scl_hcnt_reg_reset,
.clock_cfg.ss_lcnt = i2c_ss_scl_lcnt_reg_reset,
。clock_cfg.fs_hcnt = I2C_FS_SCL_HCNT_REG_RESET,
。clock_cfg.fs_lcnt = I2C_FS_SCL_LCNT_REG_RESET,
。restart_en = I2C_RESTART_ENABLE, // Restart condition enabled
。speed = I2C_SPEED_STANDARD,
。mode = I2C_MODE_MASTER, // Master Mode
.ddr_mode = i2c_addressing_7b,// 7位寻址
/ *当读/写进行时指定的设备地址允许在同一I2C总线上存在多个设备* /
.Address = 0x68,//目标/从地址(1101000 for mcp3422)
.tx_fifo_level = 1,
。rx_fifo_level = 1,
};
const uint8_t read_config = 0x10;// 00010000.
UINT8_T *数据;//Buffer where data are stored
uint16_t len = 1;//数据缓冲区的长度
// *USER_Variables&Prototype_END *//
void i2c_test(void);
/**
****************************************************************************************
int main(空白)
{
system_init();
i2c_test();
//while(1);
}
void i2c_test(void)
{
printf_string(UART,“\ n \ r \ n \ r ************”);
printf_string(UART, "\n\r* I2C TEST *\n\r");
printf_string(UART,“************* \ n \ r”);
// bool isnewtempvalue = 1;
//float temp = read_MCP3422(&isNewTempValue);
i2c_init(&i2c_cfg);
int ret =读取(read_config,data,len);
if(0 != ret){
printf_string(UART, "\n\n\r*return after readFun = "); // Debug output
printf_byte(UART,RET);
}
}
static int read(uint8_t addr, uint8_t * const data, uint8_t len)
{
int ret;
/ *设置寄存器地址以读取* /
if ((ret =i2cm_write(mcp3422_i2c_slave_addr,&addr,sizeof(addr),false))== 0){
/ *读取地址* /
RET =.i2cm_read(MCP3422_I2C_SLAVE_ADDR, data, len, true);
}
return ret;
}
int i2cm_write(uint8_t dev_addr, uint8_t const * const buffer, uint8_t len, bool add_stop)
{
int ret = 0;
uint16_t bytesSent;
i2c_abort_t abrt_code;
uint32_t flags = I2C_F_NONE;
if (add_stop) {
flags = I2C_F_WAIT_FOR_STOP | I2C_F_ADD_STOP;
}
/ *总线上的每个I2C设备都有一个唯一的地址,在我们沟通之前设置为* /
set_dev_addr(dev_addr);
/* Perform blocking write */
bytesSent =i2c_master_transmit_buffer_sync(buffer,len,&abrt_code,flags);
if((i2c_abort_none!= abrt_code)||(Bytessent!= Len)){
RET = -1;
}
printf_string(UART, "\n\rreturn after mTrans = "); // Debug output
printf_byte(UART,RET);
printf_string(UART, "\n\rData bytes sent = "); // Debug output
printf_byte(UART,BYTESSENT);
printf_string(UART,“\ n \ rdata sent =”);//调试输出
printf_byte(UART,Buffer [0]);
return ret;
}
int i2cm_read (uint8_t dev_addr, uint8_t * const哒ta, uint8_t len, bool add_stop)
{
int ret = 0;
uint16_t bytesReceived;
i2c_abort_t abrt_code;
uint32_t flags = I2C_F_NONE;
if (add_stop) {
标志= i2c_f_add_stop;
}
/ *总线上的每个I2C设备都有一个唯一的地址,在我们沟通之前设置为* /
set_dev_addr(dev_addr);
/* Performing blocking read */
bytesreceived =.i2c_master_receive_buffer_sync(data,len和abrt_code,flags);
if((abrt_code!= i2c_abort_none)||(bytesreceived!= len)){
RET = -1;
}
PRINTF_STRING(UART,“MRECE =”\ n \ n \ rreturn之后);//调试输出
printf_byte(UART,RET);
printf_string(UART, "\n\rData bytes received = "); // Debug output
printf_byte(UART,BYTESRECERED);
printf_string(UART,“\ n \ rdata收到=”);//调试输出
printf_byte(UART, *data);
return ret;
}
静态void set_dev_addr(uint8_t addr)
{
/ *只有当控制器被禁用时才可以设置设备地址* /
i2c_set_controller_status(i2c_controller_disable);
/ *启用或禁用控制器时有两个IC_CLK延迟* /
while(i2c_get_controller_status() != I2C_CONTROLLER_DISABLE);
i2c_set_target_address(i2c_cfg.address);
i2c_set_controller_status(i2c_controller_enable);
/ *启用或禁用控制器时有两个IC_CLK延迟* /
while ((i2c_get_controller_status() != I2C_CONTROLLER_ENABLE));
}
我如下所示的输出:
************
* I2C测试*
************
MTRANS = 00后返回
数据字节发送= 01
Data sent = 10
MRECE = FF后返回
收到的数据字节= 00
Data received = 48
*return after readFun = FF
/ *****************************************
在i2c_master_receive_buffer_sync(data,len和abrt_code,flags);function call, Did I need to pass as a value ofabrt_code.argument..?
2. In my code, I am not passing anyabrt_code.争论和我得到了-1as ret value in below status check. I am not able to understand why?
if((abrt_code!= i2c_abort_none)||(bytesreceived!= len)){
RET = -1;
}
3. Ini2c_master_receive_buffer_sync();function ini2c.cwe are directly checking in if conditionabrt_code.如果条件的价值。作为我的理解,它正在检查“i2c_abort_t abrt_code;”。which don't have any value. Can you please explain to me If I misunderstand anywhere?
if (abrt_code){
*abrt_code.= ret;
}
4.I2C_INIT(CFG);函数应在后面调用system_init();function right..? But, in your EEPROM_Example you haven't called anyi2c_init(); function。
3. I think most of the customers are facing the issues with I2C interface. Can you provide any simple example code for I2C communication with the sensors, so that it will be helpful for developing I2C sensor interface with the DA14531_MOD.
ThankYou
D.ravikiran.
嗨Ravikiran4,
抱歉在您的论坛线程中跳跃,但有一个SW示例,展示了如何使用I2C块。你看过那个吗?
Here is the link to download it :DA14531-DA14585-586读取I2C加速度计BLE
您使用的是哪个例子?另外,是否可以使用逻辑分析仪收费探测I2C线路并提供快照?
让我再次检查你的整个论坛线程。
谢谢,PM_DIALOG.