你好,
I could not find any document talking about functionality of the peripherals of 14580 (or others) and how to set them up for different options.
I2C,SPI,A / D,PWM,....等。
有人能点me to such document please?
Keywords:
设备:
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
你好,
我已经看到了这些文件。
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.
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
Example : I want to command a sensor with I2C. I need to send command write then eventual read . Read can be of max N bytes.
I dont know how to set the bits and bytes in the I2C registers to send and receive because it is not written anywhere !.
What functions of the i2c_eeprom example are usable in this case ?
谢谢 !
你好,
I don't believe that the I2C functions of the i2c_eeprom example is a great starting point for a sensor driver. I have been using the example below which better explains how to attack I2C:
/ ****************************************************************************************
* MACROS
****************************************************************************************/
// I2C helper macros
#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_actity()(getword16(i2c_status_reg)&mst_actity)
#define WAIT_FOR_RECEIVED_BYTE() while(!GetWord16(I2C_RXFLR_REG))
/ * ---------------------------------------------------------------------------
|@brief Initializes the I2C interface with the provide slave address
|
|@param [in] slave_address,i2c从地址与之通信
|
|@return void.
---------------------------------------------------------------------------*/
void i2c_init(uint8_t slave_address)
{
// Initialize the I2C with the address provided as argument
// todo:支持10bit寻址
setbits16(clk_per_reg,i2c_enable,1);//为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,1);//设置速度。标准速度= 1,快速= 2
SetBits16(I2C_CON_REG, I2C_10BITADDR_MASTER, 0); // Set addressing mode. 7bit = 0, 10bit= 1
setword16(i2c_tar_reg,slave_address&0xff);//设置从设备地址
SetWord16(I2C_ENABLE_REG, 0x1); // Enable the I2C controller
而(getword16(i2c_status_reg)&0x20);//等待I2C主FSM闲置
}
//
/ * ---------------------------------------------------------------------------
|@brief扫描从设备的I2C总线进行奴隶设备
|
|@param[in] extended, if true: Response will include potential I2C slave device IDs
|@param[in] remote, originator of the scan command
|
|@return void.
---------------------------------------------------------------------------*/
void i2c_scan(bool扩展,bool remote)
{
char temp_str[255] = {0};
char response_str [255] = {0};
uint8_t response_idx = 0;
// Run through all I2C addresses (7bit addressing only!)
for(uint8_t i = 0x01; i < 0x7F; i++)
{
//设置下一个从地址
i2c_init(我);
SEND_I2C_COMMAND(0x00 & 0x3FF); // Transmit Address on bus
等待_while_i2c_fifo_is_full();//等待i2c tx fifo已满
send_i2c_command(0x0100&0x3ff);//发送读取寄存器0x00
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty
wait_until_no_master_actity();// Make sure Master has finished
//我们是否收到了任何数据?
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)
// Extended scan. Report address and register 0x00 (device_id)
sprintf(temp_str, "0x%02X=>0x%02X,",i,device_id);
别的
// Normal scan => report address
sprintf(temp_str, "0x%02X,",i);
memcpy(&response_str [response_idx],temp_str,strlen(temp_str));
//警告:如果在总线上提供超过50个I2C设备,则会失败
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)
respond(response_str,strlen(response_str),remote);
//禁用i2c.
SetWord16(I2C_ENABLE_REG, 0x0); // Disable the I2C controller
SetBits16(CLK_PER_REG, I2C_ENABLE, 0); // Disable clock for I2C
}
//
/ * ---------------------------------------------------------------------------
|@brief Send I2C slave memory address
|
|@param[in] address of the I2C slave memory
---------------------------------------------------------------------------*/
void i2c_send_address(uint8_t地址_to_send)
{
send_i2c_command(地址_to_send&0xff);//设置地址LSB,写访问
}
//
/ * ---------------------------------------------------------------------------
|@brief Reads single byte from I2C slave.
|
|@param[in] address, Memory address to read the byte from.
|
|@return Read byte.
---------------------------------------------------------------------------*/
INT8_T I2C_READ_BYTE(UINT8_T地址)
{
i2c_send_address(address & 0x3FF);
等待_while_i2c_fifo_is_full();// Wait if Tx FIFO is full
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();//确保大师已完成
返回(0xff&getword16(i2c_data_cmd_reg));//获得收到的字节
}
//
/ * ---------------------------------------------------------------------------
|@brief将单个字节写入i2c从属。
|
|@param[in] address, Memory address to write the byte to.
|@param [in] wr_data,编写的数据。
|
|@return void。
---------------------------------------------------------------------------*/
void i2c_write_byte(uint16_t address, uint8_t wr_data)
{
i2c_send_address(address);
等待_while_i2c_fifo_is_full();//等待i2c tx fifo已满
SEND_I2C_COMMAND(wr_data & 0xFF); // Send write data
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty
wait_until_no_master_actity();// wait until no master activity
}
//
/ * ---------------------------------------------------------------------------{
|@brief从i2c从站读取数据
|
|@param[in] hw_address, HW address of I2C slave device
|@param[in] reg_address, Register address to be read
|@param [in] num_bytes,要读取的字节数
|@param [in]远程,read命令的始发者
|
|@return void.
---------------------------------------------------------------------------*/
void i2c_read(uint16_t hw_address,uint16_t reg_address, uint8_t num_bytes, bool remote)
{
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);
别的
Sprintf(str,“,0x%02x”,数据);
Sprintf(Temp_str,“%s%s”,temp_str,str);
}
sprintf(temp_str,"%s\n\rOK",temp_str);
respond(temp_str,strlen(temp_str),remote);
}
//
/ * ---------------------------------------------------------------------------
|@brief Writes data to a register address of an I2C slave
|
|@param[in] hw_address, HW address of I2C slave device
|@param[in] reg_address, Register address to write to
|@param [in]数据,数据写入
|@param [in]远程,read命令的始发者
|
|@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.
好的,这似乎正在寻找什么。我会试一试。
我不知道为什么你没有在SDK的文档和库中添加这个!!,这个论坛的许多人都会很开心。市场上有这么多的I2C设备,每个I2C设备都有自己的结构和协议。
thank you!
Hello , where do I find these functions
sprintf(temp_str,"%s\n\rOK",temp_str);
respond(temp_str,strlen(temp_str),remote);
Sorry I mean respond() and respond_ok()
你好,
sprintf is from the stdlib library (just #include "stdlib.h") - really useful when you want to dump data to a user or during debugging.
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.
我同意这应该将其添加到文档中 - 用于快速教程的有用材料。
你好,ok , this is clear .
在上面的代码中,
......................
void i2c_write_byte(uint16_t address, uint8_t wr_data)
{
i2c_send_address(address);
等待_while_i2c_fifo_is_full();//等待i2c tx fifo已满
SEND_I2C_COMMAND(wr_data & 0xFF); // Send write data
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty
wait_until_no_master_actity();// wait until no master activity
}
The TAR register contains the address of the slave and the DATA_CMD register contains the data to send . i2c_send_address(address) will write the address to the DATA_CMD register and then SEND_I2C_COMMAND(wr_data..) will do the same ! .
这是一个错误还是我错过了什么?
SHould all go through the DATA_CMD_REG? i.e. address of target and data to send?
如果是,则tar_reg位0:7的范围是多少?
What is simply the mechanism to :
1-send one command to a slave?
Command could be read, write, reset , ..
2- Read N. bytes from a slave device?
所有没有中断,只是为了让它变得简单。
谢谢 !
Hi sjabir2004,
IC_TAR寄存器包含从设备的地址,在I2C驱动程序中,设备将首先写入模块的寄存器地址,即它想要读取/写入data_cmd,然后,在data_cmd中放置数据传输。I2C_tar是设备本身的地址,在I2C初始化期间设置了设备地址的设置。
Thanks MT_dialog
Hello
The I2C_TAR contains the address of the i2c DEVICE to which the DA14580 would write to.
data_cmd_reg中包含要与设备进行通信的数据。
当我写入data_cmd_reg任何数据时,在I2C总线上,您首先拥有I2C_TAR_REG,然后是I2C_DATA_REG内容。
如果我将从地址写入data_cmd_reg,你将在公共汽车上有两次的地址!!
如果总线上有单个I2C设备,则需要一次加载tar_reg一次,然后将数据写入data_cmd_reg然后我获取地址 - >发送到设备的数据,
这就是我在内存示波器上看到的。
Am I missing something here ?
Hi sjabir2004,
What do you mean ? if you write the slave address of the device in the DATA_CMD_REG the module will send the I2C_TAR_REG (which is the address of the module) and then will send the data in the DATA_CMD_REG which is again the address of the module. You just need to initialize the I2C with the device that you want to communicate and and then each time you write something in the DATA_CMD_REG the address of the device will be on the bus followed along with the operation (read/write) followed by the data in the DATA_CMD_REG. After a stop or a restart condition when the i2c will start a new transaction the address of the device will be on the bus again.
Thanks MT_dialog
你好,
i am using SDK 5.0.4 .in order to check security feature in DA14580 device i have to store bond data in EEPROM. while writing a byte in to EEPROM i am facing a problem of i2c_wait_until_eeprom_ready() function .it affects the debugging.
if((getword16(sys_stat_reg)&dbg_is_up)== dbg_is_up)
__asm(“bkpt#0 \ n”);
my code was shown below like this,
************************************************************************************
/ ************************************************************
*为键数据存储选择内存介质:
*
* - spi flash(#define user_cfg_app_bond_db_use_spi_flash)
* - I2C EEPROM (#define USER_CFG_APP_BOND_DB_USE_I2C_EEPROM)
* - cache only (define nothing)
*
* Select only one option.
************************************************************
* /
#undef user_cfg_app_bond_db_use_spi_flash.
#define USER_CFG_APP_BOND_DB_USE_I2C_EEPROM
静态内联void bond_db_load_ext(void)
{
#f定义(user_cfg_app_bond_db_use_spi_flash)
bond_db_load_flash();
#elif定义(user_cfg_app_bond_db_use_i2c_eeprom)
bond_db_load_eeprom();
#endif
}
#elif定义(user_cfg_app_bond_db_use_i2c_eeprom)
静态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;
return I2C_NO_ERROR;
}
//检查要从a(max_size x 8)I2C EEPROM的读取的最大字节
if (size > I2C_EEPROM_SIZE - address)
{
tmp_size = I2C_EEPROM_SIZE - address;
*bytes_read = tmp_size;
}
别的
{
tmp_size = size;
*bytes_read = size;
}
if (i2c_wait_until_eeprom_ready() != I2C_NO_ERROR)
{
return I2C_7B_ADDR_NOACK_ERROR;
}
//一次读取32个字节
while (tmp_size >= 32)
{
read_data_single(&rd_data_ptr,地址,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);
}
return 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
send_i2c_command(0x08);//制作假人
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty
wait_until_no_master_actity();// Wait until no master activity
tx_abrt_source = GetWord16(I2C_TX_ABRT_SOURCE_REG); // Read the I2C_TX_ABRT_SOURCE_REG register
GetWord16(I2C_CLR_TX_ABRT_REG); // Clear I2C_TX_ABRT_SOURCE register
if ((tx_abrt_source & ABRT_7B_ADDR_NOACK) == 0)
{
return I2C_NO_ERROR;
}
}
return I2C_7B_ADDR_NOACK_ERROR;
}
注意:如果我在Sysram中加载了键数据,则它正常工作。IE,
#undef user_cfg_app_bond_db_use_spi_flash.
#undef USER_CFG_APP_BOND_DB_USE_I2C_EEPROM
请给出一个有价值的建议,以避免这个问题。谢谢。
Hi 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