How to verify there is proper I2C connection is happened between DA14531 MOD and (I2C device) MCP3422

Learn MoreFAQsTutorials

4 posts / 0 new
Last post
ravikiran4
Offline
Last seen:1 month 3 weeks ago
加入:2020-08-05 09:45
How to verify there is proper I2C connection is happened between DA14531 MOD and (I2C device) MCP3422

Hello Dialog,

我正在尝试传达DA14531 Mod和MCP3422(模拟到数字转换器)。但是,我无法识别是否建立了I2C连接。你能帮我这个问题吗?

//*USER_CODE_START* //

const i2c_cfg_t *cfg;
// ________设置主站______ //
i2c_restart_t restart = i2c_restart_enable;//启用重新启动条件
i2c_addressing_t addr_mode = I2C_ADDRESSING_7B; // 7-bit addressing
uint16_t target_addr = 0x68; // Address of target/slave (1101000 for MCP3422)
//________Master Receive Buffer______//
uint8_t *data; //Address of the buffer where data are stored
uint16_t len = 1; //Length of the data buffer
i2c_abort_t *abrt_code; //(If not NULL, the status of the operation ) - I2C_ABORT_NONE
uint32_t flags; //

//*USER_CODE_END* //

//*main.c CODE_START* //

system_init();

i2c_init(cfg);
i2c_setup_master(restart, addr_mode, target_addr);
uint16_t bytesReceived = i2c_master_receive_buffer_sync((uint8_t*)&data, len, abrt_code, I2C_F_ADD_STOP);
printf_string(UART,“\ n \ rdata字节接收=”);//调试输出
printf_byte (UART,bytesReceived);
printf_string(UART, "\n\rData received = "); // Debug output
printf_byte(UART,*数据);

UINT16_T BYTESSENT = I2C_MASTER_TRANSMIT_BUFFER_SYNC((UINT8_T *)数据,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 = "); // Debug output
printf_byte(UART,*数据);

//*main.c caic_end.* //

1. In "i2c_master_receive_buffer_sync((uint8_t *)和数据,len,abrt_code,i2c_f_add_stop);" function I haven't defined any value to "abrt_code". Is it ok? If not what valu I can pass to it?

2.在上述功能中,我已经过了“i2c_f_add_stop." as flag argument. Is it ok?

3.在这两种情况下,我在我的TERA术语中得到了相同的输出(如下所述)(无论是从MCP3422连接到DA14531的SDA,SCL,VCC和GND引脚是否连接到DA14531)。我无法理解我的代码是工作的。如果我错过了,请告诉我?

Data bytes received = 00
收到的数据= 50
Data bytes sent = 01
Data sent = 50

我希望你很快就会回应这个问题。

Thank You in advance

D.RAVIKIRAN

Device:
PW_Dialog
Offline
Last seen:2 days 16 hours ago
工作人员
加入:2019-04-03 02:54
哈维基兰,

哈维基兰,

The "abrt_code" in "i2c_master_receive_buffer_sync((uint8_t *)和数据,len,abrt_code,i2c_f_add_stop);“可用于在空无效时检查操作状态。请检查此值以获取状态。

你通过了 ”i2c_f_add_stop." in the function is no problem, that's just make STOP condition at the end of transaction.

The value you printed are expected, data sent should be same as the data received, and the sent bytes is 1 that's the length passed in the function. As mentioned the abrt_code need to be checked for the status.

布罗尔,

PW_Dialog

ravikiran4
Offline
Last seen:1 month 3 weeks ago
加入:2020-08-05 09:45
Thank you for your response,

Thank you for your response,

As per your answer, I have checked the abrt_code status and I have also modified some other error&status checks also.

// * user_variables&prototype_start * //
static 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);
static int read(uint8_t, uint8_t * const, uint8_t);

静态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条件
.speed = i2c_speed_standard,
.mode = i2c_mode_master,//主模式
.addr_mode = I2C_ADDRESSING_7B, // 7-bit addressing
/* Device address specified when read/write takes place allowing multiple devices to be present on the same I2C bus */
.address = 0x68, // Address of target/slave (1101000 for MCP3422)
.tx_fifo_level = 1,
.rx_fifo_level = 1,
};

const uint8_t READ_CONFIG = 0x10; // 00010000
uint8_t *data; //Buffer where data are stored
uint16_t len = 1; //Length of the data buffer

// * user_variables&prototype_end * //

void i2c_test(void);

/ **
****************************************************************************************

int main (void)
{
system_init();
i2c_test();

//虽然(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(READ_CONFIG, data, len);
if(0 != ret){
printf_string(UART,“\ n \ n \ r * readfun = rest return reter;//调试输出
printf_byte (UART,ret);
}
}

静态int read(uint8_t addr,uint8_t * const数据,uint8_t len)
{
int ret;

/* Set register address to read from */
if ((ret =i2cm_write(MCP3422_I2C_SLAVE_ADDR, &addr, sizeof(addr), false)) == 0) {
/* Read data at the address */
ret =i2cm_read(mcp3422_i2c_slave_addr,data,len,true);
}
返回Ret;
}

int i2cm_write(uint8_t dev_addr,uint8_t const * const buffer,uint8_t len,bool add_stop)
{
int ret = 0;
uint16_t bytesentent;
i2c_abort_t abrt_code;

UINT32_T标志= I2C_F_NONE;
if(add_stop){
flags = I2C_F_WAIT_FOR_STOP | I2C_F_ADD_STOP;
}
/* Each I2C device on the bus has a unique address, set this before we communicate */
set_dev_addr(dev_addr);
/ *执行阻塞写* /
Bytessent =.i2c_master_transmit_buffer_sync(buffer, len, &abrt_code, flags);

if ((I2C_ABORT_NONE != abrt_code) || (bytesSent != len)) {
ret =-1;
}
printf_string(UART,MTRANS = N \ RRETURN =“);//调试输出
printf_byte (UART,ret);
printf_string(UART, "\n\rData bytes sent = "); // Debug output
printf_byte (UART,bytesSent);
printf_string(UART, "\n\rData sent = "); // Debug output
printf_byte (UART,buffer[0]);
返回Ret;
}

int i2cm_read(uint8_t dev_addr, uint8_t * const data, uint8_t len, bool add_stop)
{
int ret = 0;
uint16_t bytesreceived;
i2c_abort_t abrt_code;

UINT32_T标志= I2C_F_NONE;
if(add_stop){
flags = I2C_F_ADD_STOP;
}
/* Each I2C device on the bus has a unique address, set this before we communicate */
set_dev_addr(dev_addr);
/ *执行阻塞读* /
bytesReceived =i2c_master_receive_buffer_sync(data, len, &abrt_code, flags);

if ((abrt_code != I2C_ABORT_NONE) || (bytesReceived != len)) {
ret =-1;
}
printf_string(UART, "\n\rreturn after mRece = "); // Debug output
printf_byte (UART,ret);
printf_string(UART,“\ n \ rdata字节接收=”);//调试输出
printf_byte (UART,bytesReceived);
printf_string(UART, "\n\rData received = "); // Debug output
printf_byte(UART,*数据);
返回Ret;
}

static void set_dev_addr(uint8_t addr)
{
/* The device address can only be set when the controller is disabled */
i2c_set_controller_status(I2C_CONTROLLER_DISABLE);
/* There is a two ic_clk delay when enabling or disabling the controller */
while(i2c_get_controller_status()!= i2c_controller_disable);

i2c_set_target_address(i2c_cfg.address);

i2c_set_controller_status(I2C_CONTROLLER_ENABLE);
/* There is a two ic_clk delay when enabling or disabling the controller */
while((i2c_get_controller_status()!= i2c_controller_enable));
}

I am getting output as below:

************
* I2C TEST *
************

return after mTrans = 00
Data bytes sent = 01
数据发送= 10
return after mRece = FF
Data bytes received = 00
收到的数据= 48

* readfun = ff后返回

/ ***************************************/

1. Ini2c_master_receive_buffer_sync(data, len, &abrt_code, flags);函数调用,我是否需要传递作为一个值abrt_code争论..?

2.在我的代码中,我没有通过任何abrt_codeargument and I am getting-1作为RET值在下面的状态检查。我无法理解为什么?

if ((abrt_code != I2C_ABORT_NONE) || (bytesReceived != len)) {
ret =-1;
}

i2c_master_receive_buffer_sync();功能在I2C.C.我们直接检查了条件abrt_codevalue in if condition. as my understanding it is checking"i2c_abort_t abrt_code;".其中没有任何价值。如果我误解任何地方,你能向我解释吗?

if(abrt_code){
* abrt_code = RET;
}

4. Thei2c_init(cfg);功能should be called after thesystem_init();功能正确..?但是,在你的eeprom_example中,你没有打电话i2c_init();功能.

3.我认为大多数客户面临着I2C接口的问题。您是否可以提供与传感器的I2C通信的任何简单示例代码,以便有助于使用DA14531_MOD开发I2C传感器接口。

谢谢你

D.RAVIKIRAN

PM_Dialog
Offline
Last seen:52 min 31 sec ago
工作人员
加入:2018-02-08 11:03
Hi ravikiran4,

Hi ravikiran4,

Sorry for jumping in your forum thread, but there is a SW Example showing how to use the I2C block. Did you take a look into that?

以下是下载它的链接:DA14531-DA14585-586 Reading I2C Accelerometer BLE

Which example are you using? Additionally, would it be possible to probe the I2C lines with a logic analyzer toll and provide a snapshot?

Let me also check your whole forum thread again.

Thanks, PM_Dialog