你好,
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,....etc.
Can anybody point me to such document please?
Keywords:
Device:
嗨sjabir2004,
请查看外围示例应用程序部分(7)的文档UM-B-050,也可以查看外围驱动程序部分(10)中的Doc UM-B-051,以获取外围设备的驱动程序雷竞技安卓下载。
谢谢mt_dialog.
你好,
I have already seen these documents.
没有描述外围设备的硬件结构以及如何设置。这些示例无法涵盖所有可能的组合和功能。
请确认缺少此文档。
嗨sjabir2004,
没有关于DA外围设备和开发的API的其他文档,有关任何其他功能的更多信息,可以在DA的数据表中找到。此外,您可能希望查看文档UM-B-005和UM-B-004以检查这些文档是否涵盖了任何其他功能。
谢谢mt_dialog.
示例:我想命令一个sensor with I2C. I need to send command write then eventual read . Read can be of max N bytes.
我不知道如何在I2C寄存器中设置位和字节以发送和接收,因为它不是写在任何地方!。
What functions of the i2c_eeprom example are usable in this case ?
Thank you !
Hi,
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:
/****************************************************************************************
*宏
****************************************************************************************/
// I2C helper macros
#define SEND_I2C_COMMAND(X) SetWord16(I2C_DATA_CMD_REG, (X))
#define wait_whille_i2c_fifo_is_full()while(!(getword16(i2c_status_reg)&tfnf))
#define wait_until_i2c_fifo_is_empty(!(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))
/*---------------------------------------------------------------------------------------
|@brief Initializes the I2C interface with the provide slave address
|
|@param[in] slave_address, The I2C slave address to communicate with
|
|@return void
---------------------------------------------------------------------------------------*/
void i2c_init(uint8_t slave_address)
{
//使用作为参数提供的地址初始化I2C
// TODO: Support 10bit addressing
SetBits16(CLK_PER_REG, I2C_ENABLE, 1); // Enable clock for I2C
setword16(i2c_enable_reg,0x0);//禁用I2C控制器
SetWord16(I2C_CON_REG, I2C_MASTER_MODE | I2C_SLAVE_DISABLE |I2C_RESTART_EN); // Slave is disabled
SetBits16(I2C_CON_REG, I2C_SPEED, 1); // Set speed. Standard speed = 1, fast = 2
setbits16(i2c_con_reg,i2c_10bitaddr_master,0);//设置寻址模式。7bit = 0,10bit = 1
SetWord16(I2C_TAR_REG, slave_address & 0xFF); // Set Slave device address
SetWord16(I2C_ENABLE_REG, 0x1); // Enable the I2C controller
while(GetWord16(I2C_STATUS_REG) & 0x20); // Wait for I2C master FSM to be IDLE
}
//
/*---------------------------------------------------------------------------------------
|@brief Scans the I2C bus for slave devices
|
|@param [in]扩展,如果为true:响应将包括潜在的i2c从设备ID
|@param[in] remote, originator of the scan command
|
|@return void
---------------------------------------------------------------------------------------*/
void i2c_scan(bool extended,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 ++)
{
// Set next slave address
i2c_init(i);
SEND_I2C_COMMAND(0x00 & 0x3FF); // Transmit Address on bus
WAIT_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();// Wait until Tx FIFO is empty
wait_until_no_master_actity();//确保大师已完成
// Did we receive any data?
if(GetWord16(I2C_RXFLR_REG) != 0)
{
//读取收到的数据(device_id)
uint8_t device_id = 0xff&getword16(i2c_data_cmd_reg);
//如果这是扩展扫描,则报告设备ID以及地址
如果(扩展)
// Extended scan. Report address and register 0x00 (device_id)
sprintf(temp_str, "0x%02X=>0x%02X,",i,device_id);
else
//正常扫描=>报告地址
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);
}
}
//附加回车返回,LineFeed和“确定”回复
sprintf(temp_str,"\n\rOK");
memcpy(&response_str[response_idx-1],temp_str,strlen(temp_str));
//显示响应(远程或本地)
respond(response_str,strlen(response_str),remote);
// Disable I2C
setword16(i2c_enable_reg,0x0);//禁用I2C控制器
setBits16(CLK_PER_REG,I2C_ENABLE,0);//禁用I2C的时钟
}
//
/*---------------------------------------------------------------------------------------
| @brief发送I2C奴隶备忘录ry address
|
|@param[in] address of the I2C slave memory
---------------------------------------------------------------------------------------*/
void i2c_send_address(uint8_t address_to_send)
{
SEND_I2C_COMMAND(address_to_send & 0xFF); // Set address LSB, write access
}
//
/*---------------------------------------------------------------------------------------
|@brief Reads single byte from I2C slave.
|
|@param [in]地址,存储地址读取字节。
|
|@return读字节。
---------------------------------------------------------------------------------------*/
INT8_T I2C_READ_BYTE(UINT8_T地址)
{
i2c_send_address(地址和0x3FF);
WAIT_WHILE_I2C_FIFO_IS_FULL(); // Wait if Tx FIFO is full
send_i2c_command(0x0100&0x3ff);//将R / W位设置为1(读取访问)
wait_until_i2c_fifo_is_empty();//等到I2C TX FIFO空
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]地址,存储字节写入的内存地址。
|@param[in] wr_data, Data to write.
|
|@return void.
---------------------------------------------------------------------------------------*/
void i2c_write_byte(uint16_t地址,uint8_t wr_data)
{
i2c_send_address(address);
WAIT_WHILE_I2C_FIFO_IS_FULL(); // Wait if I2C Tx FIFO is full
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 Reads data from an I2C slave
|
|@param[in] hw_address, HW address of I2C slave device
|@param[in] reg_address, Register address to be read
|@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 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];
如果(i == 0)
Sprintf(str,“0x%02x”,数据);
else
sprintf(str,",0x%02X",data);
sprintf(temp_str,"%s%s",temp_str,str);
}
sprintf(temp_str,"%s\n\rOK",temp_str);
响应(temp_str,strlen(temp_str),远程);
}
//
/*---------------------------------------------------------------------------------------
|@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,注册地址写入
|@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远程)
{
i2c_init(hw_address);
I2C_WRITE_BYTE(REG_ADDRESS,WR_DATA);
respons_ok(远程);
}
//
我希望这有帮助。
好的,这似乎是我的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.
thank you!
你好,我在哪里找到了这些functions
sprintf(temp_str,"%s\n\rOK",temp_str);
响应(temp_str,strlen(temp_str),远程);
Sorry I mean respond() and respond_ok()
Hi,
sprintf is from the stdlib library (just #include "stdlib.h") - really useful when you want to dump data to a user or during debugging.
这两个响应函数只是我已经实现的一组函数,以将数据转储到串行端口。您可以使用UART2和ARCH_PRINTF在代码中执行此操作。
I agree that this should be added to the documentation - useful material for a quick tutorial.
你好, ok , this is clear .
In your code above ,
。。。。。。。。。。............
void i2c_write_byte(uint16_t地址,uint8_t wr_data)
{
i2c_send_address(address);
WAIT_WHILE_I2C_FIFO_IS_FULL(); // Wait if I2C Tx FIFO is full
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 ! .
Is this a mistake or I am missing something?
SHould all go through the DATA_CMD_REG? i.e. address of target and data to send?
If yes , what is the scope of TAR_REG bits 0:7?
什么是以下机制:
1-send one command to a slave?
可以读取,写入,重置命令。
2- Read N. bytes from a slave device?
All without interrupts , just to get it easy.
Thank you !
嗨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.
谢谢mt_dialog.
你好
The I2C_TAR contains the address of the i2c DEVICE to which the DA14580 would write to.
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.
我在这里错过了什么?
嗨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.
谢谢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,
************************************************************************************
/************************************************************
*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)
*- cache only (define nothing)
*
*仅选择一个选项。
************************************************************
*/
#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();
# elif (USER_CFG_APP_BOND_DB_USE_I2C_EEPROM定义)
bond_db_load_eeprom();
#endif
}
# elif (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地址,UINT32_T大小,UINT32_T * BYTES_READ)
{
uint32_t tmp_size;
if(size == 0)
{
* bytes_read = 0;
return I2C_NO_ERROR;
}
// Check for max bytes to be read from a (MAX_SIZE x 8) I2C EEPROM
if (size > I2C_EEPROM_SIZE - address)
{
tmp_size = i2c_eeprom_size - 地址;
* bytes_read = tmp_size;
}
else
{
tmp_size = size;
* bytes_read = size;
}
if(i2c_wait_until_eeprom_ready()!= i2c_no_error)
{
return I2C_7B_ADDR_NOACK_ERROR;
}
// Read 32 bytes at a time
而(tmp_size> = 32)
{
read_data_single(&rd_data_ptr, address, 32);
地址+ = 32;//更新读取的基本地址
tmp_size - = 32;//更新TMP_SIZE以进行剩余的字节读取
}
if (tmp_size)
{
read_data_single(&rd_data_ptr,地址,tmp_size);
}
return I2C_NO_ERROR;
}
i2c_error_code i2c_wait_until_eeprom_ready(void)
{
uint16_t tx_abrt_source;
//检查是否已收到ACK
for (uint32_t i = 0; i < I2C_MAX_RETRIES; i++)
{
SEND_I2C_COMMAND(0x08); // Make a dummy access
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;
}
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.
Hi ajay98,
i2c_wait_until_eeprom_ready()通过发送0x08字节来轮询设备,直到设备用ACK响应。你能在调试模式下运行代码,并指示在哪个点I2c_wait_until_eeprom_ready()代码被困?此外,您使用的是SDK的哪个示例?这是一个定制的实施吗?是否可以在SDK的BLE_APP_SECURY示例中复制它?
我还建议您使用问题创建一个新的论坛线程,因为这是非常旧的。
谢谢,PM_DIALOG.