16 posts / 0 new
Last post
sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
documentation

Hello,

我找不到任何谈论14580(或其他)的外围设备功能的文件以及如何为不同的选项设置它们。

I2C, SPI, A/D, PWM,....etc.

有人能指出我这样的文件吗?

关键词:
Device:
MT_dialog
Offline
Last seen:1天23小时前
Staff
加入:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

Please have a look at the documents UM-B-050 at the peripheral examples applications section (7) and also you can have a look to the doc UM-B-051 in the peripheral drivers section (10) for the drivers of the peripherals.

Thanks MT_dialog

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
Hello,

Hello,

I have already seen these documents.
There is no description of the hardware structure of the peripherals and how these can be setup . The examples cannot cover all possible combinations and functionalities.

Please confirm that this document is missing.

MT_dialog
Offline
Last seen:1天23小时前
Staff
加入:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

There are no other documents concerning the da peripherals and the developed APIs, for more info about any additional functionalities can be found in the da's datasheet. Also you might want to have a look at the documents UM-B-005 and UM-B-004 to check if those documents cover any additional functionalities.

Thanks MT_dialog

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
Example : I want to command a

示例:我想使用i2c命令传感器。我需要发送命令写入然后最终读取。读取可以是max n字节。

I dont know how to set the bits and bytes in the I2C registers to send and receive because it is not written anywhere !.

在这种情况下,I2C_EEPROM示例的功能是可用的?

Thank you !

MHv_Dialog
Offline
Last seen:2周5天前
Staff
加入:2013-12-06 15:10
Hi,

Hi,

我不认为I2C_EEPROM示例的I2C功能是传感器驱动程序的一个很好的起点。我一直在使用下面的例子,更好地解释了如何攻击I2C:

/ ****************************************************************************************
* MACROS
*****************************************************************************************
// i2c Helper宏
#define SEND_I2C_COMMAND(X) SetWord16(I2C_DATA_CMD_REG, (X))
#define WAIT_WHILE_I2C_FIFO_IS_FULL() while(!(GetWord16(I2C_STATUS_REG) & TFNF))
#define WAIT_UNTIL_I2C_FIFO_IS_EMPTY() while(!(GetWord16(I2C_STATUS_REG) & TFE))
#define WAIT_UNTIL_NO_MASTER_ACTIVITY() while(GetWord16(I2C_STATUS_REG) & MST_ACTIVITY)
#define WAIT_FOR_RECEIVED_BYTE() while(!GetWord16(I2C_RXFLR_REG))

/*---------------------------------------------------------------------------------------
|@brieie初始化提供从地址的I2C接口
|
|@param[in] slave_address, The I2C slave address to communicate with
|
|@return void
------------------------------------------------------------------------------------------------- * /
void i2c_init(uint8_t slave_address)
{
//Initialize the I2C with the address provided as argument
//TODO: Support 10bit addressing
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);//从站被禁用
SetBits16(I2C_CON_REG, I2C_SPEED, 1); // Set speed. Standard speed = 1, fast = 2
SetBits16(I2C_CON_REG, I2C_10BITADDR_MASTER, 0); // Set addressing mode. 7bit = 0, 10bit= 1
SetWord16(I2C_TAR_REG, slave_address & 0xFF); // Set Slave device address
setword16(i2c_enable_reg,0x1);//启用I2C控制器
while(GetWord16(I2C_STATUS_REG) & 0x20); // Wait for I2C master FSM to be IDLE
}
//

/*---------------------------------------------------------------------------------------
|@brief Scans the I2C bus for slave devices
|
|@param[in] extended, if true: Response will include potential I2C slave device IDs
|@param [in]远程,扫描命令的始发者
|
|@return void
------------------------------------------------------------------------------------------------- * /
void i2c_scan(bool extended,bool remote)
{
char temp_str[255] = {0};
char response_str[255] = {0};
uint8_t response_idx=0;

//遍历所有I2C地址(仅限7bit寻址!)
for(uint8_t i = 0x01; i < 0x7F; i++)
{
//Set next slave address
i2c_init(i);

send_i2c_command(0x00&0x3ff);//在总线上传输地址
等待_while_i2c_fifo_is_full();//Wait if I2C Tx FIFO is full
SEND_I2C_COMMAND(0x0100 & 0x3FF); // Send read register 0x00
wait_until_i2c_fifo_is_empty();//等到TX FIFO是空的
wait_until_no_master_actity();//Make sure Master has finished

//Did we receive any data?
if(GetWord16(I2C_RXFLR_REG) != 0)
{
/ /读取接收到的数据(device_id)
uint8_t device_id =0xFF & GetWord16(I2C_DATA_CMD_REG);
//If this is an extended scan then report the device ID as well as the address
if(extended)
//扩展扫描。报告地址和注册0x00(device_id)
Sprintf(Temp_str,“0x%02x => 0x%02x,”,i,device_id);
else
//Normal scan => report address
sprintf(temp_str, "0x%02X,",i);
memcpy(&response_str[response_idx],temp_str,strlen(temp_str));
//Warning: will fail if more than 50 I2C devices available on bus
response_idx += strlen(temp_str);
}

}
//Append Carriage-return, Linefeed and 'OK' to response
sprintf(temp_str,"\n\rOK");
memcpy(&response_str [response_idx-1],temp_str,strlen(temp_str));
//Display response (remote or locally)
响应(response_str,strlen(response_str),远程);

//Disable I2C
SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller
SetBits16(CLK_PER_REG, I2C_ENABLE, 0); // Disable clock for I2C

}
//

/*---------------------------------------------------------------------------------------
|@brief发送i2c从存储器地址
|
|@param [in] I2C从存储器的地址
------------------------------------------------------------------------------------------------- * /
void i2c_send_address(uint8_t address_to_send)
{

SEND_I2C_COMMAND(address_to_send & 0xFF); // Set address LSB, write access
}
//

/*---------------------------------------------------------------------------------------
|@brief从i2c从站读取单个字节。
|
|@param[in] address, Memory address to read the byte from.
|
|@return Read byte.
------------------------------------------------------------------------------------------------- * /
int8_t i2c_read_byte(uint8_t address)
{
i2c_send_address(address & 0x3FF);
等待_while_i2c_fifo_is_full();//等待TX FIFO已满
SEND_I2C_COMMAND(0x0100 & 0x3FF); // Set R/W bit to 1 (read access)
wait_until_i2c_fifo_is_empty();//Wait until I2C Tx FIFO empty
wait_until_no_master_actity();//Make sure master has finished
return (0xFF & GetWord16(I2C_DATA_CMD_REG)); // Get received byte
}
//

/*---------------------------------------------------------------------------------------
|@brief Writes single byte to I2C slave.
|
|@param[in] address, Memory address to write the byte to.
|@param[in] wr_data, Data to write.
|
|@return void.
------------------------------------------------------------------------------------------------- * /
void i2c_write_byte(uint16_t address, uint8_t wr_data)
{
i2c_send_address(地址);
等待_while_i2c_fifo_is_full();//Wait if I2C Tx FIFO is full
send_i2c_command(wr_data&0xff);//发送写入数据
wait_until_i2c_fifo_is_empty();//等到TX FIFO是空的
wait_until_no_master_actity();//等到没有主活动
}
//

/*---------------------------------------------------------------------------------------
|@brief Reads data from an I2C slave
|
|@param [in] hw_address,i2c从设备的HW地址
|@param [in] reg_address,要读取的注册地址
|@param[in] num_bytes, Number of bytes to read
|@param[in] remote, originator of the read command
|
|@return void
------------------------------------------------------------------------------------------------- * /
void i2c_read(uint16_t hw_address,uint16_t reg_address,uint8_t num_bytes,bool远程)
{
char temp_str[255] = {0};
i2c_init(hw_address);
for(uint8_t i=0;i{
uint8_t data = i2c_read_byte(reg_address+i);
char str[10];
if(i==0)
sprintf(str,"0x%02X",data);
else
sprintf(str,",0x%02X",data);
sprintf(temp_str,"%s%s",temp_str,str);
}
Sprintf(Temp_str,“%s \ n \ rok”,temp_str);
respond(temp_str,strlen(temp_str),remote);
}
//

/*---------------------------------------------------------------------------------------
|@brief将数据写入I2C从站的寄存器地址
|
|@param [in] hw_address,i2c从设备的HW地址
|@param[in] reg_address, Register address to write to
|@param[in] data, Data to write
|@param[in] remote, originator of the read command
|
|@return void
------------------------------------------------------------------------------------------------- * /
void i2c_write(uint16_t hw_address,uint16_t reg_address, uint16_t wr_data, bool remote)
{
i2c_init(hw_address);
i2c_write_byte(reg_address,wr_data);
respond_ok(remote);
}
//

I hope this helps.

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
Ok this seems what I was

Ok this seems what I was looking for. I will give it a try.

I don't know why don't you add this in the documentation and libraries of the SDK !!, many people in this forum will be happy. There are so many I2C devices on the market, each with own structure and protocol.

谢谢你!

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
Hello , where do I find these

您好,我在哪里找到了这些功能
Sprintf(Temp_str,“%s \ n \ rok”,temp_str);
respond(temp_str,strlen(temp_str),remote);

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
对不起,我的意思是回复()和

对不起,我的意思是回复()和respond_ok()

MHv_Dialog
Offline
Last seen:2周5天前
Staff
加入:2013-12-06 15:10
Hi,

Hi,

SprIntf来自STDLIB库(只是#include“stdlib.h”) - 当您想要将数据转储到用户或调试期间,真正有用。

The two respond functions are just a set of functions that i have implemented to dump the data to a serial port. You can use UART2 and arch_printf to do this in your code.

I agree that this should be added to the documentation - useful material for a quick tutorial.

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
你好,好的,这很清楚。

你好,好的,这很清楚。
In your code above ,
。。。。。。。。。。............
void i2c_write_byte(uint16_t address, uint8_t wr_data)
{
i2c_send_address(地址);
等待_while_i2c_fifo_is_full();//Wait if I2C Tx FIFO is full
send_i2c_command(wr_data&0xff);//发送写入数据
wait_until_i2c_fifo_is_empty();//等到TX FIFO是空的
wait_until_no_master_actity();//等到没有主活动
}
Tar寄存器包含从站的地址,DATA_CMD寄存器包含要发送的数据。I2C_SEND_ADDRESS(地址)会将地址写入DATA_CMD寄存器,然后send_i2c_command(wr_data ..)会这样做!。

Is this a mistake or I am missing something?
都应该通过data_cmd_reg?即,要发送目标和数据的地址?
If yes , what is the scope of TAR_REG bits 0:7?

What is simply the mechanism to :
1 - 向奴隶发送一个命令?
Command could be read, write, reset , ..
2-从从设备读取N.字节?
All without interrupts , just to get it easy.
Thank you !

MT_dialog
Offline
Last seen:1天23小时前
Staff
加入:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

The IC_TAR register contains the address of the slave device, in the i2c driver the device will first write the register address of the module, that it wants to read/write to the DATA_CMD, and then, place in the DATA_CMD register the data to be transmitted. The I2C_TAR is the address of the device itself the setting of your device address is set during the i2c initialization.

Thanks MT_dialog

sjabir2004@yahoo.com
Offline
Last seen:5 years 1 month ago
加入:2015-09-18 22:13
Hello

Hello

I2C_tar包含DA14580将写入的I2C设备的地址。
The DATA_CMD_REG contains the data to communicate to the DEVICE.

When I write to the DATA_CMD_REG any data , on the i2c bus you have first the I2C_TAR_REG followed by the I2C_DATA_REG content.

If I write the slave address to the DATA_CMD_REG , you will have the address TWO times on the bus !!

If there is single i2c DEVICE on the bus , one needs to load the TAR_REG once and then writes data to DATA_CMD_REG then I get address-->Data sent to the device,

This is what I see on the memory oscilloscope.

Am I missing something here ?

MT_dialog
Offline
Last seen:1天23小时前
Staff
加入:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

你什么意思 ?如果在data_cmd_reg中编写设备的从站地址,则模块将发送I2C_TAR_REG(这是模块的地址),然后将在DATA_CMD_REG中发送数据,该数据再次成为模块的地址。您只需要使用要通信的设备初始化I2C,然后每次在data_cmd_reg中写入内容时,设备的地址将在总线上遵循操作(读/写),然后是数据在data_cmd_reg中。停止或重新启动条件后,I2C将启动新事务时,设备的地址将再次在总线上。

Thanks MT_dialog

ajay98
Offline
Last seen:2 months 3 weeks ago
加入:2018-07-10 12:12
Hello,

Hello,
我正在使用SDK 5.0.4。在DA14580设备中检查安全功能,我必须在EEPROM中存储绑定数据。在向EEPROM写入字节时,我面临i2c_wait_until_eeprom_ready()函数的问题。它会影响调试。
if ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP)
__asm("BKPT #0\n");

我的代码如下所示,
************************************************************************************
/ ************************************************************
* Select memory medium for bond data storage:
*
* - SPI FLASH (#define USER_CFG_APP_BOND_DB_USE_SPI_FLASH)
* - I2C EEPROM (#define USER_CFG_APP_BOND_DB_USE_I2C_EEPROM)
* - 仅缓存(定义任何内容)
*
* Select only one option.
************************************************************
*/
#undef USER_CFG_APP_BOND_DB_USE_SPI_FLASH
#define user_cfg_app_bond_db_use_i2c_eeprom.

static inline void bond_db_load_ext(void)
{
#if defined (USER_CFG_APP_BOND_DB_USE_SPI_FLASH)
bond_db_load_flash();
# elifdefined (USER_CFG_APP_BOND_DB_USE_I2C_EEPROM)
bond_db_load_eeprom ();
#万一
}

# elifdefined (USER_CFG_APP_BOND_DB_USE_I2C_EEPROM)

static void bond_db_load_eeprom(void)
{
uint32_t bytes_read;

i2c_eeprom_init(I2C_SLAVE_ADDRESS, I2C_SPEED_MODE, I2C_ADDRESS_MODE, I2C_ADDRESS_SIZE);

i2c_eeprom_read_data((uint8_t *)&bdb,app_bond_db_data_offset,sizeof(struct bond_db),&bytes_read);
ASSERT_ERROR(bytes_read == sizeof(struct bond_db));

i2c_eeprom_release();
}

i2c_error_code i2c_eeprom_read_data(uint8_t *rd_data_ptr, uint32_t address, uint32_t size, uint32_t *bytes_read)
{
uint32_t tmp_size;

if (size == 0)
{
*bytes_read = 0;
返回i2c_no_error;
}

//Check for max bytes to be read from a (MAX_SIZE x 8) I2C EEPROM
if(size> i2c_eeprom_size - 地址)
{
tmp_size = I2C_EEPROM_SIZE - address;
*bytes_read = tmp_size;
}
else
{
tmp_size = size;
*bytes_read = size;
}

if (i2c_wait_until_eeprom_ready() != I2C_NO_ERROR)
{
返回i2c_7b_addr_noack_error;
}

//Read 32 bytes at a time
while (tmp_size >= 32)
{
read_data_single(&rd_data_ptr, address, 32);

address += 32; // Update base address for read
tmp_size -= 32; // Update tmp_size for bytes remaining to be read
}

if (tmp_size)
{
read_data_single(&rd_data_ptr, address, tmp_size);
}

返回i2c_no_error;
}

i2c_error_code i2c_wait_until_eeprom_ready(void)
{
uint16_t tx_abrt_source;

//Check if ACK is received
for (uint32_t i = 0; i < I2C_MAX_RETRIES; i++)
{
SEND_I2C_COMMAND(0x08); // Make a dummy access
wait_until_i2c_fifo_is_empty();//等到TX FIFO是空的
wait_until_no_master_actity();//等到没有主活动
tx_abrt_source = getword16(i2c_tx_abrt_source_reg);//读取i2c_tx_abrt_source_reg寄存器
getword16(i2c_clr_tx_abrt_reg);//清除i2c_tx_abrt_source寄存器
if((tx_abrt_source&abrt_7b_addr_noack)== 0)
{
返回i2c_no_error;
}
}
返回i2c_7b_addr_noack_error;
}

note: if i loaded the bond data in sysram, it is working fine. i.e,
#undef USER_CFG_APP_BOND_DB_USE_SPI_FLASH
#undef user_cfg_app_bond_db_use_i2c_eeprom.

please give a valuable suggesssition to avoid this problem.advance thanks.

PM_Dialog
Offline
Last seen:23 hours 34 min ago
Staff
加入:2018-02-08 11:03
嗨ajay98,

嗨ajay98,

The i2c_wait_until_eeprom_ready() is polling the device via sending a 0x08 byte until the device responds with an ACK. Can you please run the code in debug mode and indicate in which point of i2c_wait_until_eeprom_ready() the code gets stuck? Also, which example of the SDK are you using? Is this a custom implementation? Would it be possible to replicate it in the ble_app_security example of the SDK?

I would also recommend you creating a new forum thread with your issue, as this one is very old.

Thanks, PM_Dialog