本文来源电子发烧友社区,作者:华仔stm32, 帖子地址:https://bbs.elecfans.com/jishu_2293777_1_1.html
官方提供的是AT命令格式,但是我原来想象的还是用模块本身获取数据然后上传给AP,这次仔细阅读了官方的源代码,at代码在PS目录下面,的at目录下面,主要有at_boot.c
、at_factory.c
、at_wiota.c
、at_wiota.h
、at_wiota_atuto_manager.c
、ati_prs.h
文件。
在at_factory.c
下面给出了示例,可以学习如何操作:
#ifdef UC8288_MODULE
#ifdef UC8288_FACTORY
#ifdef *RT_THREAD*
#include
#include
#endif
#include
#include "uc_adda.h"
#include "string.h"
#include "ati_prs.h"
#include "at.h"
#ifdef *L1_FACTORY_FUNC*
#include "uc_wiota_api.h"
#endif
enum factory_can_write_read_type
{
FACTORY_CAN_WRITE = 0,
FACTORY_CAN_READ,
};
enum factory_command_type
{
FACTORY_WIOTA = 0,
FACTORY_GPIO, // 1
FACTORY_I2C,// 2
FACTORY_AD,// 3
FACTORY_DA,// 4
FACTORY_UART1,//5
FACTORY_PWM, // 6
FACTORY_CAN,
};
#define DAC_DEV_NAME "dac"
#define ADC_DEV_NAME "adc"
#define AHT10_I2C_BUS_NAME "hw_i2c"
#define UART1_DEV_NMAE "uart1"
#define PWM_DEV_NAME "pwm0"
#define CAN_DEV_NAME "can1"
#define AT24C02_ADDR 0xA0
static rt_err_t write_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint8_t *data)
{
rt_uint8_t buf[8];
struct rt_i2c_msg msgs;
rt_uint32_t buf_size = 1;
buf[0] = reg; //cmd
if (data != RT_NULL)
{
buf[1] = data[0];
buf[2] = data[1];
buf[3] = data[2];
buf[4] = data[3];
buf_size = 5;
}
msgs.addr = AT24C02_ADDR;
msgs.flags = RT_I2C_WR;
msgs.buf = buf;
msgs.len = buf_size;
if (rt_i2c_transfer(bus, &msgs, 1) == 1)
{
return RT_EOK;
}
else
{
return -RT_ERROR;
}
}
static rt_err_t read_regs(struct rt_i2c_bus_device *bus, rt_uint8_t len, rt_uint8_t *buf)
{
struct rt_i2c_msg msgs;
msgs.addr = AT24C02_ADDR;
msgs.flags = RT_I2C_RD;
msgs.buf = buf;
msgs.len = len;
if (rt_i2c_transfer(bus, &msgs, 1) == 1)
{
return RT_EOK;
}
else
{
return -RT_ERROR;
}
}
static int at_test_i2c(void)
{
rt_device_t dev;
unsigned char set_data[4] = {1,2,3,4};
unsigned char get_data[4] = {0};
int num = 0;
dev = rt_device_find(AHT10_I2C_BUS_NAME);
if(RT_NULL == dev)
{
rt_kprintf("rt_device_find i2c fail
");
return 1;
}
if(RT_EOK != write_reg((struct rt_i2c_bus_device*)dev, 0, set_data))
{
rt_kprintf("write_reg i2c fail
");
return 2;
}
if(RT_EOK != read_regs((struct rt_i2c_bus_device*)dev, 4, get_data))
{
rt_kprintf("read_regs i2c fail
");
return 3;
}
for(num = 0; num < 4; num++)
{
if (set_data[num] != get_data[num])
{
rt_kprintf("i2c data match fail. num=%d, %d!= %d
", num, set_data[num], get_data[num]);
return 4;
}
}
return 0;
}
static int at_test_ad(unsigned int channel)
{
rt_adc_device_t adc_dev;
rt_uint32_t value;
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
if (RT_NULL == adc_dev)
{
rt_kprintf("ad find %s fail
", ADC_DEV_NAME);
return -1;
}
rt_adc_enable(adc_dev, channel);
value = rt_adc_read(adc_dev, channel);
rt_adc_disable(adc_dev, channel);
return value;
}
static int at_test_da(unsigned int channel, unsigned int value)
{
rt_dac_device_t dac_dev;
dac_dev = (rt_dac_device_t)rt_device_find(DAC_DEV_NAME);
if (RT_NULL == dac_dev)
{
rt_kprintf("da find fail
");
return -1;
}
rt_dac_enable(dac_dev, channel);
rt_dac_write(dac_dev, channel, value);
//rt_dac_disable(dac_dev, channel);
return 0;
}
static int at_factory_test_uart1(void)
{
static rt_device_t serial;
unsigned char send_data[4] = {"1234"};
unsigned char recv_data[4] = {0};
serial = rt_device_find(UART1_DEV_NMAE);
if (serial)
return 1;
if ( RT_EOK != rt_device_open(serial, RT_DEVICE_OFLAG_RDWR))
{
rt_kprintf("uart open fail
");
return 2;
}
rt_device_write(serial, 0, send_data, sizeof(send_data)/sizeof(unsigned char));
if(rt_device_read(serial, 0, recv_data, sizeof(recv_data)/sizeof(unsigned char)) < 1)
{
rt_kprintf("uart read fail
");
return 3;
}
rt_device_close(serial);
return strcmp((const char *)send_data, (const char *)recv_data);
}
static int at_factory_test_pwm(int channel, unsigned int period)
{
struct rt_device_pwm *pwm_dev;
pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
if (RT_NULL == pwm_dev)
{
return 1;
}
rt_pwm_set(pwm_dev, channel, period, 0);
rt_pwm_enable(pwm_dev, channel);
rt_pwm_disable(pwm_dev,channel);
return 0;
}
static int at_factory_test_can(int type, void *data)
{
static rt_device_t can_dev;
struct rt_can_msg msg = {0};
//struct rt_can_msg rxmsg = {0};
rt_err_t res;
rt_size_t size;
can_dev = rt_device_find(CAN_DEV_NAME);
if (RT_NULL == can_dev)
{
rt_kprintf("find %s failed!
", CAN_DEV_NAME);
return 1;
}
res = rt_device_open(can_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);
if(res != RT_EOK)
{
rt_kprintf("open %s failed!
", CAN_DEV_NAME);
return 2;
}
if (type == FACTORY_CAN_WRITE)
{
msg.id = 0x78;
msg.ide = RT_CAN_STDID;
msg.rtr = RT_CAN_DTR;
msg.len = 8;
msg.data[0] = 0x00;
msg.data[1] = 0x11;
msg.data[2] = 0x22;
msg.data[3] = 0x33;
msg.data[4] = 0x44;
msg.data[5] = 0x55;
msg.data[6] = 0x66;
msg.data[7] = 0x77;
size = rt_device_write(can_dev, 0, &msg, sizeof(msg.data));
if (size == 0)
{
return 2;
}
}
else if (type == FACTORY_CAN_READ)
{
int len = 0;
//rxmsg.hdr = -1;
rt_device_read(can_dev, 0, data, 8);
rt_kprintf("recv data:");
for(len = 0; len < 8; len++)
{
rt_kprintf("%x", *((int*)(data+len)));
}
rt_kprintf("
");
}
return 0;
}
static at_result_t at_factory_setup(const char* args)
{
int type = 0, data = 0, data1 = 0;
args = parse ((char*)(++args),"ddd", &type, &data, &data1);
if (!args)
{
return AT_RESULT_PARSE_FAILE;
}
rt_kprintf("type = %d,data=%d,data1 = %d
", type, data, data1);
switch(type)
{
case FACTORY_WIOTA:
{
#ifdef *L1_FACTORY_FUNC*
if(!factory_msg_handler(data,data1)) {
return AT_RESULT_FAILE;
}
#endif
break;
}
case FACTORY_GPIO:
{
rt_base_t pin = data;
rt_base_t value = data1 & 0x1;
rt_pin_write( pin, value);
break;
}
case FACTORY_I2C:
{
if (at_test_i2c())
return AT_RESULT_FAILE;
break;
}
case FACTORY_AD:
{
unsigned int ch = data;
int result = at_test_ad(ch);
if (result < 0)
return AT_RESULT_NULL;
switch(ch)
{
case ADC_CONFIG_CHANNEL_TEMP_B:
{
float val = 0.00;
val = (float)((float)1.42/4.0 + (result - 2048)* (float)1.42/2048.0/8.0);
at_server_printfln("+FACTORY=%d,0.%d", type, val*100.0);
break;
}
default:
{
at_server_printfln("+FACTORY=%d,%d", type, result);
break;
}
}
break;
}
case FACTORY_DA:
{
unsigned int ch = data;
unsigned int val = data1;
if(at_test_da(ch, val) < 0)
return AT_RESULT_NULL;
break;
}
case FACTORY_UART1:
{
if(at_factory_test_uart1())
return AT_RESULT_NULL;
break;
}
case FACTORY_PWM:
{
int channel = data;
unsigned int period = data1;
if (at_factory_test_pwm( channel, period))
return AT_RESULT_NULL;
break;
}
case FACTORY_CAN:
{
char recv[8] = {0};
if (at_factory_test_can(data, recv))
return AT_RESULT_NULL;
if (data == FACTORY_CAN_READ)
{
at_server_printf("+FACTORY=%d,", type);
at_send_data(recv, sizeof(recv)/sizeof(recv[0]));
}
break;
}
default:
return AT_RESULT_REPETITIVE_FAILE;
}
return AT_RESULT_OK;
}
AT_CMD_EXPORT("AT+FACTORY", "=,,", RT_NULL, RT_NULL, at_factory_setup, RT_NULL);
#endif
#endif
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
御芯微
+关注
关注
4文章
56浏览量
3322
发布评论请先 登录
相关推荐
【正点原子STM32H7R3开发套件试用体验】开发套件开箱报告
STM32从入门到跑路了。
而且官方提供的资料和例程,那也是特别的丰富:
正点原子STM32H7R3开发套件确实是一套非常值得拥有,非常值得学习研究的开发套件。
发表于 12-12 00:54
【xG24 Matter开发套件试用体验】深入了解Silicon Labs xG24 Matter开发套件
今天把收到的xG24 Matter开发套件给大家做个详细的介绍,Silicon Labs-芯科科技公司最新推出的一款具有智能和机器学习硬件加速功能的无线物联网产品评估xG24 Matter开发
发表于 08-27 20:23
【xG24 Matter开发套件试用体验】1-基本情况介绍
参加[Silicon Labs xG24 Matter开发套件免费试用]活动,拿到了期待的EFR32xG24 Explorer 开发套件(一个基于 EFR32MG24 片上系统的小封装开发
发表于 07-17 12:39
【xG24 Matter开发套件试用体验】初上手开发板和官方IDE
本帖最后由 jf_56450220 于 2024-7-13 22:57 编辑
前言首先非常感谢电子发烧友论坛提供的xG24 Matter开发套件试用。根据datasheet了解到这块开发板拥有
发表于 07-13 22:20
【xG24 Matter开发套件试用体验】初识xG24 Matter开发套件
今天带刚收到xG24 Matter开发套件的快递,为大家做个xG24 Matter开发套件的视频介绍,带大家认识一下这款xG24 Matter开发套件。
EFR32xG24 Explorer
发表于 07-11 23:31
【xG24 Matter开发套件试用体验】+开机启动
xG24 Matter开发套件试用体验:
1.EFR32xG24 Explorer 套件是一个基于 EFR32MG24 片上系统的小封装开发和评估平台。EFR32xG24 Explor
发表于 07-11 14:05
如何使用wifi进行自组网开发?
您好,我正在使用wifi进行自组网开发,但是demo中的都是借助于路由器进行自组网的,我想知道能否有方案能够只通过WIFI就完成自组网
发表于 06-28 15:36
御芯微能源大会畅谈WIoTa技术应用,IP核级自主物联网芯片助力产业数字化转型
【南京】5月23号,在刚刚落下帷幕的第六届综合能源服务落地实践峰会上,国内领先的集成电路设计企业——重庆御芯微信息技术有限公司再度成为全场焦点。公司副总裁李明栋先生发表了一场主题为《低功耗能源物联网通信
发力万物智联,御芯微官宣7款WIoTa方案产品助力产业升级
RFID读写器模组。模组采用邮票孔封装,只有23mmx20mm小尺寸,UCM606L读取距离达到5m以上。 据悉,重庆御芯微成立于2018年,是一家IP核级全自主创新的平台型物联网芯片设计企业,这家企业自研底层射频、DSP、编
御芯微携合作伙伴发布新款RFID模组和7款WIoTa方案产品
【深圳,福田】4月14日,在第二届深圳国际传感器与应用技术展览会期间,御芯微在深圳福田会展中心7号展馆隆重举行了其最新系列产品的发布会。此次发布会吸引了来自全国各地的行业专家、合作伙伴、媒体代表
御芯微携合作伙伴发布新款RFID模组和7款WIoTa方案产品
4月14日,在第二届深圳国际传感器与应用技术展览会期间,御芯微s首先一款中长距的UHF RFID模组,接连发布了基于WIoTa协议的7款大容
发表于 04-15 20:19
•437次阅读
迈来芯推出专为简化汽车动态RGB-LED设计的开发套件ADK81116
迈来芯推出应用开发套件ADK81116。该套件专为简化汽车动态RGB-LED应用的开发流程而设计。这款全面而高效的解决方案配备了预加载的可配置固件,从而无需为此专门
【LicheeRV-Nano开发套件试用体验】+智能平板开发
首先感谢Sipeed矽速科技和电子发烧友给与的这次机会,得以试用LicheeRV-Nano开发套件,并与大家共同分享与学习。
鉴于试用报告格式调整,后面亦按要求展现。
申请理由:
发表于 03-06 23:05
【LicheeRV-Nano开发套件试用连载体验】+ 实现三麦克纳姆轮小车自主导航
LicheeRV-Nano开发套件的免费试用新品体验。
此次试用也将按照新的规则发布报告进行试用体验。
1、官方试用要求:
发表于 03-03 14:20
评论