11 posts / 0 new
Last post
Arun Chettoor
Offline
Last seen:6年2个月前
Joined:2014-06-21 08:20
I2C code

I am interfacing an accelerometer with I2C bus interface. The datasheet of the accelerometer insist that the start condition need to be sent at a particular time to get the data. So what is the procedure or code to make the start and stop condition in the I2C section from software. Is it possible to know whether the start condition has been successfully transmitted on the bus. If so which register I should monitor. I am using the expert development board and using the P00 and P01 for the scl and sda pins. Thank you!

Dialog_HM
Offline
Last seen:5个月1周前
Joined:2014-04-01 16:07
Hi Arun,

Hi Arun,

Q1您使用了哪些传感器?
Q2您是否检查了SDK软件中的Periphiral I2C部分。

The way it works is shown below:

我不知道使用了哪些芯片,但如果我看看MC3410规格,
以下情况应该是如下:

例如the XOUT (see MC3410-spec) is to be read via I2C.
■开始
■地址(= 0x4c + r / w = 0)
■data 0x0D
■重启
■address (= 0x4C + R/W = 1)
■data in0 (address = 0x0D)
■数据in1(地址= 0 x0e)…通过自动分辨ase
■停止

Now we have to convert this to a working program:
see User Manual UM-B-004

… // part of main program

#define xout0 0x0d // bit 0 ... 7数组[0]
#define XOUT1 0x0E // bit 8 … 15 array[1]
#define地址-IIC 0x4C // IIC-Address的MC3410

unsigned char array[2];

i2c_eeprom_init(ADDRESS-IIC, I2C_7BIT_ADDR,I2C_1BYTE_ADDR);
i2c_eeprom_read_data(array,xout0,2);

// data is stored in array[0] (LSB) and array[1] (MSB)

I hope this is clear how it works.

关于软件的建议(在UM-B-004中使用EEPROM-DATA-READ + INFO)正在解决问题。

Arun Chettoor
Offline
Last seen:6年2个月前
Joined:2014-06-21 08:20
嗨,谢谢你的回复。

嗨,谢谢你的回复。I am using adxl345 as the sensor. I need to generate a start byte and in the datasheet of DA1458 it is mentioned that the writing to IC_TAR will generate a start byte if the SPECIAL and GC_OR_START is set. So i written this code:

SETWORD16(I2C_TAR_REG,0xC53); //激活重启 - 11&10位设置,0x53是传感器的7位地址。

而(getBits16(i2c_intr_stat_reg,r_start_det)== 0); //检测开始字节已发送或不发送

But the code is stuck at the above while section and it is not able to detect or it is not producing a start byte. I connected everything as sensor datasheet says and I am only getting acknowledgement from the sensor. I also tried do while loop to continuously trigger the IC_TAR, but still the same output.

The sequence that sensor need is:
*开始字节
*编写slaveaddr +写
* read acknowledgement
* write reg addr to be read
* read acknowledgement
*读取数据.//在这里有问题。在RX FIFO中没有数据如此选中,发现未生成启动字节。
* read acknowledgement
* 停止

我当前的init序列是:

SetBits16(CLK_PER_REG, I2C_ENABLE, 1); // enable clock for I2C
SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller
SetWord16(I2C_CON_REG, I2C_MASTER_MODE | I2C_SLAVE_DISABLE | I2C_RESTART_EN); // Slave is disabled
SetBits16(I2C_CON_REG, I2C_SPEED, speed); // Set speed 100
// setbits16(i2c_con_reg,i2c_10bitaddr_master,address_mode);//自7位以来不会设置寻址模式
SetWord16(I2C_TAR_REG, GC_OR_START|SPECIAL|(dev_address & 0x3FF)); // added START bit and SPECIAL bit to 1 for sending START to accelerometer.
setword16(i2c_enable_reg,0x1);//启用I2C控制器
while( (GetWord16(I2C_STATUS_REG) & 0x20) != 0 );

Arun Chettoor
Offline
Last seen:6年2个月前
Joined:2014-06-21 08:20
Can you help me?

Can you help me?

Dialog_HM
Offline
Last seen:5个月1周前
Joined:2014-04-01 16:07
你好arun,

你好arun,

I will check your info today.

您是否使用任何I2C-Protocol-Analyzer?例如Saleae或其他品牌。
Then you really know that your software is working.

最好的问候

Dialog_HM
Offline
Last seen:5个月1周前
Joined:2014-04-01 16:07
Hi Arun,

你好arun,

通过ADXL345阅读手册以下是以下内容:
* cs =高
* if ALT_ADDRESS = high => 0x3A = write and 0x3B = read
* if ALT_ADDRESS = low => 0xA6 = write and 0xA7 = read
* use proper values for pull-up resistors for the SDA and the SCL lines (e.g. 4k7)
* ID-code of the ADXL345 = 0xE5. This can be read out of the chip, to check whether the protocol works.

最好的问候,嗯

Arun Chettoor
Offline
Last seen:6年2个月前
Joined:2014-06-21 08:20
Thank You so much for the

非常感谢你的回复。我正在读取ADXL的ID代码,并且开始字节不是发送。我给出了适当的拉动电阻,我只得到了确认。关于你写的任何东西是8位地址。因此,我首先通过在数据表中提到的(在I2C_DATA_CMD_REG上)发送此8位地址来启动代码。但这里的问题是 -
* ic_tar仅包含7位和10位寻址的IC_tar。所以这里我不能在阅读和写作之前给出8位地址。所以我在这里给出了7位寻址。这是个问题吗?
*在DA14580数据表中,提到,如果我们将写入IC_tar Statte,则将发送特殊(位11)和GC_OR_START(位10)。因此,在设置这些后,应提出开始字节中断。我没有得到它。这是部分 -
SETWORD16(I2C_TAR_REG,0xC53); //激活重启 - 11&10位设置,0x53是传感器的7位地址。

而(getBits16(i2c_intr_stat_reg,r_start_det)== 0); //检测开始字节已发送或不发送

你能让我清楚这些点吗?

Arun Chettoor
Offline
Last seen:6年2个月前
Joined:2014-06-21 08:20
Gone through the output pins

Gone through the output pins of the DA14580 after initialization of the pins as i2c peripheral and found that it is not giving any signals. Please give me a test code to initiate the start condition of the I2C code.

Dialog_HM
Offline
Last seen:5个月1周前
Joined:2014-04-01 16:07
你好arun,

你好arun,

现在在DESC上有芯片(ADXL345Z)。
看看我能做什么,解决你的问题。

HM

Arun Chettoor
Offline
Last seen:6年2个月前
Joined:2014-06-21 08:20
Hi,

Hi,
很高兴你得到了IC并为之工作。我让UART正常工作,同样地配置了I2C引脚。我通过示波器来了解任何启动信号是否发生(而SCL(高)SDA(低))。但是明确地知道它不是从配置的I2C引脚中提供任何信号。我们是否需要使用值设置I2C时钟的定时。我的意思是下面:
setword16(ic_ss_scl_lcnt,0x08);
SetWord16(IC_SS_SCL_HCNT,0x06);

But while I was running the debugger I came to know that these lines are making the code to redirect to hardware_handler.c and to the section :
if ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP)
__asm("BKPT #0\n");

请告诉我是否需要解锁任何寄存器值以更改这些值。

Dialog_HM
Offline
Last seen:5个月1周前
Joined:2014-04-01 16:07
Hi

Hi

It is possible to use the I2C EEPROM drivers for controlling other I2C-applications-chips, non EEPROM. A temperature sensor (SE95) example is shown below.

*** step 1. open the SDK-software:
sdk ... \ peripheral_examples ... da14580_peripheral_setup.uvproj

*** step 2. see: periph_setup.h:
将硬件_configuration_index(。)更改为'1'。

/* Test Definition - Select the Configuration that matches your H/W setup
*---------------------------------------------------------
*(0)带有UART的SPI闪存
*(1)I2C EEPROM与UART
* (2) QUADRATURE ENCODER WITH BUZZER AND UART
*---------------------------------------------------------
*/
//硬件配置<0 => SPI闪存具有UART <1 =>带UART <2 =>正交编码器,定时器和蜂鸣器与UART
#define HARDWARE_CONFIGURATION_INDEX (1) // 1 => I2C

***第3步。

add new software in: eeprom_test.c (at the beginning of the file)

挥发性int16_t温度;
volatile int ii;

//测试外围设备SE95温度传感器
//地址= 1001 a2 a1 a0 r / w => 7bitaddress = 0x48 ... 0x48 + 7 = 0x4f

i2c_eeprom_init(0x48, I2C_STANDARD, I2C_7BIT_ADDR, I2C_1BYTE_ADDR);

// reading internal ID-number:
ii = i2c_eeprom_read_byte(0x05); // test reading ID-value = 0xA1

//读取温度
btrd = i2c_eeprom_read_data(rd_data, 0, 2);

温度= 256 * RD_DATA [0] + RD_DATA [1];
temperature = temperature / 8; // shift 3 bits to right

// ***

I tested this software on the acceration sensor and it worked.
Just make the proper connections and fill in different 7bit slave address etc .

add the following lines in the upper example:

i2c_eeprom_init(0x53, I2C_STANDARD, I2C_7BIT_ADDR, I2C_1BYTE_ADDR);
....
btrd = i2c_eeprom_read_data(rd_data, 29, 29); // start at addres29 ... address 57 = 29 locations

read variables via rd_data[0] ... rd_data[28]

我希望这能为您做出,读出加速度传感器。

{hm}

Topic locked