最近2个星期都在搞PWM输出的问题,主要是对于ARM的CMSIS库的熟悉和移植;整个过程中遇到了很多问题,就一些比较经典的问题,给大家分享一下;
1.首先,我们安装完RSL10的pack后,可以选择i2c_cmsis_drive例程
2. 选择完,该例程后,编译是无法通过的,因为RSL10的pack中并没有包含 ARM CMSIS PACK;而该例程中I2C是采用的ARM Cortex M3的I2C外设,因此需要安装 ARM CMSIS PACK;
https://developer.arm.com/tools-and-software/embedded/cmsis 去该网站,然后跳转到github上下载最新的pack, 然后安装到ON 开发环境中;即可正常编译;
3. 移植pca9685
应该注意,
3.1 I2C从机地址:如果PCA9685的I2C地址是0x40, 那么在arm cmsis库中,也应该是0x40, 而不是0x80;
3.2 采用arm cmsis库的I2C驱动时,不需要我们去添加R/W bit,驱动会自动添加;
bool pca9685_write_u8(pca9685_handle_t *handle, uint8_t address, uint8_t value)
{
uint8_t data[] = {address, value};
//return i2c->MasterTransmit(handle->device_address, data, 2, false) == 0;
i2c->MasterTransmit(handle->device_address, data, 2, false);
while (i2c->GetStatus().busy);
return true;
}
bool pca9685_write_data(pca9685_handle_t *handle, uint8_t address, uint8_t *data, size_t length)
{
if (length == 0 || length > 4) {
return false;
}
uint8_t transfer[5];
transfer[0] = address;
memcpy(&transfer[1], data, length);
i2c->MasterTransmit(handle->device_address, transfer, length + 1, false);
while (i2c->GetStatus().busy);
return true;
//return i2c->MasterTransmit(handle->device_address, transfer, length + 1, false) == 0;
}
bool pca9685_read_u8(pca9685_handle_t *handle, uint8_t address, uint8_t *dest)
{
i2c->MasterTransmit(handle->device_address, &address, 1, false);
while (i2c->GetStatus().busy);
i2c->MasterReceive(handle->device_address, dest, 1, false);
while (i2c->GetStatus().busy);
return true;
// if ( i2c->MasterTransmit(handle->device_address, &address, 1, false) != 0) {
// return false;
// }
//
// return i2c->MasterReceive(handle->device_address, dest, 1, false) == 0;
}
4. PWM波形输出
后续,计划学习BLE 协议,这个之前没有接触过,个人觉得还是比较有挑战的..
引用: hehung 发表于 2021-5-28 14:41 厉害,IIC的代码能发一下嘛?我调试这块一直返回未完成故障
引用: 传媒学子 发表于 2021-5-30 19:15 i2c_cmsis_driver.rar
谢谢[点赞]
原来这个开发这么困难,IIC通信估计我也用得到!