Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
LED
睿擎工业开发平台
睿擎工业开发平台--iic扩展IO驱动实现LED驱动翻转闪烁
发布于 2025-06-16 20:45:16 浏览:38
订阅该版
[tocm] # 使用iic扩展IO驱动实现LED驱动翻转闪烁 ## 使用自定iic工具扫描iic设置 0x38就是iic扩展并口 0x51就是rtc时钟芯片 ```c available commands: list i2c list [-v] scan i2c scan [-b
] [-r
] read i2c read [-b
] [-a
] [-r
] [-l
] write i2c write [-b
] [-a
] [-r
] [-d
] Use 'i2c
--help' to get help for a specific command i2c: command failed -1. msh />i2c scan -b i2c0 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- 11 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- msh /> msh /> ``` IIC 扫描结果  ## 硬件设计  ## **TCA9534A**芯片介绍 是iic的IO扩展的地址就是0x38 ### 芯片地址  ### 控制寄存器和读写寄存器  极性反转寄存器(寄存器2)允许配置寄存器定义的输入引脚进行极性反转。如果该寄存器中的某个位被设置(用1表示),则相应的端口引脚极性将被反转;如果该位被清除(用0表示),则保持端口引脚的原始极性不变。  ##配置寄存器  配置寄存器(寄存器3)用于设置I/O引脚的方向。如果该寄存器中的某个位被设置为1,相应的端口引脚将被启用为输入模式,并配备高阻抗输出驱动器。如果该寄存器中的某个位被清零为0,相应的端口引脚将被启用为输出模式。 ### 读写时序  ## 写代码 根据芯片的手册,io的驱动流程是 1. 设置io方形 2. 设置输出寄存器 创建一个线程实现LED循环翻转,蓝色灯 ```c void test_entry(void *parameter) { rt_uint8_t buf[2] = {0}; struct rt_i2c_msg msg; int val=0; struct rt_i2c_bus_device *i2c_bus = (struct rt_i2c_bus_device *)parameter; while (1) { msg.addr = 0x38; msg.flags = RT_I2C_WR; msg.buf = buf; msg.len = 2; buf[0] = 0x01; buf[1] = val?0xff:0; if (rt_i2c_transfer(i2c_bus, &msg, 1) == 1) { // return RT_EOK; } val=!val; rt_thread_mdelay(1000); } } static rt_err_t led_TCA9534A(int argc,char *argv[]) { struct rt_i2c_bus_device *i2c_bus = RT_NULL; if(argc!=2) { LOG_E("param is error\n"); return -1; } i2c_bus = rt_i2c_bus_device_find("i2c0"); rt_uint8_t buf[2] = {0}; struct rt_i2c_msg msg; int val=0; sscanf(argv[1],"%d",&val); buf[0] = 0x03; buf[1] = 0; msg.addr = 0x38; msg.flags = RT_I2C_WR; msg.buf = buf; msg.len = 2; if (!rt_i2c_transfer(i2c_bus, &msg, 1) == 1) { LOG_E("transfer error\n"); } buf[0] = 0x01; buf[1] = val?0xff:0; if (!rt_i2c_transfer(i2c_bus, &msg, 1) == 1) { // return RT_EOK; LOG_E("transfer error\n"); } struct rt_thread *thd= rt_thread_create("test", test_entry, i2c_bus,1024, 10, 10); rt_thread_startup(thd); return (RT_EOK); } MSH_CMD_EXPORT(led_TCA9534A, led_TCA9534A); ```  # 普通的gpio使用 官方的`#define LED 160`这个led就是使用iic扩展io实现的 ## 红色LED灯控制 LED编号=gpio0(A,B,C,D),每个分组8个,gpio0_d0==24 ```c #include
#include
#define DBG_TAG "example.gpio" #define DBG_LVL DBG_INFO #include
#define LED 160 #define LED_READ 24//红色LED, rt_err_t gpio_output_example(void) { rt_uint32_t count = 10; rt_ubase_t pin_num = 0; pin_num = (LED); rt_pin_mode(pin_num, PIN_MODE_OUTPUT); rt_pin_mode(LED_READ, PIN_MODE_OUTPUT); LOG_I("gpio output startup"); while (count--) { rt_pin_write(pin_num, PIN_HIGH); rt_pin_write(LED_READ, PIN_HIGH); rt_thread_mdelay(1000); rt_pin_write(pin_num, PIN_LOW); rt_pin_write(LED_READ, PIN_LOW); rt_thread_mdelay(1000); } LOG_I("gpio output end"); return RT_EOK; } MSH_CMD_EXPORT(gpio_output_example, gpio output example); ```
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
chejia12
这家伙很懒,什么也没写!
文章
12
回答
1
被采纳
0
关注TA
发私信
相关文章
1
应用开发如何包含头文件
2
STM32F03RC跑RTT标准版 没有运行
3
为什么 Count 的值不连续和间隔为 7?
4
请求LED.C/H文件
5
RT-thread 如何被当做“单片机”,控制小灯的亮灭?
6
ART-PI Smart User 运行LED 程序崩溃
7
agile led软件包怎么使用
8
AT32F423开发板呼吸灯无作用,只有一个灯亮
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
6
五分钟玩转RT-Thread新社区
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
Bootloader
AT
Hardfault
CAN总线
ART-Pi
FinSH
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
FAL
RTC
rt-smart
I2C_IIC
UART
cubemx
ESP8266
BSP
ota在线升级
WIZnet_W5500
PWM
packages_软件包
flash
freemodbus
GD32
潘多拉开发板_Pandora
ADC
keil_MDK
定时器
flashDB
编译报错
ulog
socket
rt_mq_消息队列_msg_queue
msh
中断
Debug
SFUD
C++_cpp
MicroPython
本月问答贡献
出出啊
1524
个答案
343
次被采纳
小小李sunny
1444
个答案
290
次被采纳
张世争
821
个答案
179
次被采纳
crystal266
555
个答案
162
次被采纳
whj467467222
1222
个答案
149
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
2
次点赞
crystal266
2
篇文章
1
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部