精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線(xiàn)課程
  • 觀(guān)看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

CPK-RA2L1評(píng)估板PMS1003

冬至子 ? 來(lái)源:快樂(lè)小鳥(niǎo) ? 作者:快樂(lè)小鳥(niǎo) ? 2023-10-11 11:40 ? 次閱讀

一、準(zhǔn)備
本篇文章主要介紹使用RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估板,使用攀藤PMS1003 作為pm2.5 ,pm10等粉塵顆粒信息采集傳感器

二、模塊信息
通過(guò)官網(wǎng)對(duì)PMS1003的介紹,可通過(guò)uart通信采集數(shù)據(jù),以及該傳感器的各項(xiàng)技術(shù)性能指標(biāo)

1.jpg

三、新建工程
根據(jù)上面了解的模塊信息,使用UART0 作為通信接口,注意波特率為:9600 ,數(shù)據(jù)包長(zhǎng)32字節(jié)

1.jpg

2.jpg

3.jpg

在RT-Thread Settings種配置好 UART驅(qū)動(dòng)程序,和打開(kāi)硬件模塊的UART0 開(kāi)關(guān)

1.jpg

在 RA Smart Configurator 種添加UART0,配置好引腳和波特率

1.jpg

四、代碼實(shí)現(xiàn)
/*

  • Copyright (c) 2006-2021, RT-Thread Development Team
  • SPDX-License-Identifier: Apache-2.0
  • Change Logs:
  • Date Author Notes
  • 2023-02-25 DYC the first version
    */
    #define DBG_SECTION_NAME "pms_series"
    #define DBG_LEVEL DBG_LOG
    #define DBG_COLOR
    #include
    #include
    #include "pms1003.h"
    #define RT_SERIAL_RB_BUFSZ 64
    #define COMM_START1 0x42
    #define COMM_START2 0x4D
    #define FRAME_HEAD1 0x00
    #define FRAME_HEAD2 0x01
    #define FRAME_LENH 0x02
    #define FRAME_LENL 0x03
    #define FRAME_RECEIVE 0x04
    #define FRAME_CHECK 0x05
    rt_err_t frame_check(pms_device_t dev,rt_uint8_t *buf,rt_uint16_t len)
    {
    rt_uint16_t sum=0;
    RT_ASSERT(dev);
    for(uint8_t i=0;i<(len-2);i++)
    {
    sum += buf[i];
    }
    if((buf[len-1] == (sum&0xFF)) && (buf[len-2] == (sum >> 8)))
    {
    dev->PM1_0_CF1 = ((rt_uint16_t)(buf[4])<<8) | buf[5];
    dev->PM2_5_CF1 = ((rt_uint16_t)(buf[6])<<8) | buf[7];
    dev->PM10_0_CF1 = ((rt_uint16_t)(buf[8])<<8) | buf[9];
    dev->PM1_0_amb = ((rt_uint16_t)(buf[10])<<8) | buf[11];
    dev->PM2_5_amb = ((rt_uint16_t)(buf[12])<<8) | buf[13];
    dev->PM10_0_amb = ((rt_uint16_t)(buf[14])<<8) | buf[15];
    dev->air_0_3um = ((rt_uint16_t)(buf[16])<<8) | buf[17];
    dev->air_0_5um = ((rt_uint16_t)(buf[18])<<8) | buf[19];
    dev->air_1_0um = ((rt_uint16_t)(buf[20])<<8) | buf[21];
    dev->air_2_5um = ((rt_uint16_t)(buf[22])<<8) | buf[23];
    dev->version = buf[len - 4];
    dev->errorCode = buf[len - 3];
    return RT_EOK;
    }
    return RT_ERROR;
    }
    rt_err_t pms_get_byte(pms_device_t dev, char data)
    {
    rt_err_t result;
    static uint8_t state = FRAME_HEAD1;
    static uint8_t cnt = 0;
    static rt_uint8_t buf[40] = {0};
    RT_ASSERT(dev);
    if(state == FRAME_HEAD1 && data == COMM_START1)
    {
    buf[cnt++] = data;
    state = FRAME_HEAD2;
    }
    else if (state == FRAME_HEAD2 && data == COMM_START2)
    {
    buf[cnt++] = data;
    state = FRAME_LENH;
    }
    else if (state == FRAME_LENH)
    {
    buf[cnt++] = data;
    state = FRAME_LENL;
    }
    else if (state == FRAME_LENL)
    {
    buf[cnt++] = data;
    state = FRAME_RECEIVE;
    }
    else if (state == FRAME_RECEIVE)
    {
    buf[cnt++] = data;
    if(cnt >= COMM_LEN - 1)
    state = FRAME_CHECK;
    }
    else if (state == FRAME_CHECK)
    {
    buf[cnt++] = data;
    state = FRAME_HEAD1;
    cnt = 0;
    result = frame_check(dev, buf, COMM_LEN);
    if (result == RT_EOK)
    {
    LOG_D("check success");
    return result;
    }
    else
    {
    LOG_E("check error");
    }
    }
    else {}
    return result;
    }
    pms_device_t pms_init(const char *uart_name)
    {
    pms_device_t dev;
    RT_ASSERT(uart_name);
    dev = rt_calloc(1, sizeof(struct pms_device));
    if (dev == RT_NULL)
    {
    LOG_E("Can't allocate memory for pms device %s",uart_name);
    return RT_NULL;
    }
    dev->serial = rt_device_find(uart_name);
    if (!dev->serial)
    {
    rt_free(dev);
    rt_kprintf("find %s failed!n", uart_name);
    }
    else
    {
    dev->config.baud_rate = BAUD_RATE_9600;
    dev->config.data_bits = DATA_BITS_8;
    dev->config.stop_bits = STOP_BITS_1;
    dev->config.parity = PARITY_NONE;
    dev->config.bit_order = BIT_ORDER_LSB;
    dev->config.invert = NRZ_NORMAL;
    dev->config.rx_bufsz = RT_SERIAL_RB_BUFSZ;
    dev->config.reserved = 0;
    rt_device_control(dev->serial, RT_DEVICE_CTRL_CONFIG, &dev->config);
    }
    return dev;
    }
    void pms_deinit(pms_device_t dev)
    {
    RT_ASSERT(dev);
    rt_free(dev);
    }
    /*
  • Copyright (c) 2006-2021, RT-Thread Development Team
  • SPDX-License-Identifier: Apache-2.0
  • Change Logs:
  • Date Author Notes
  • 2023-02-25 DYC the first version
    */
    #ifndef SRC_PMS1003_H_
    #define SRC_PMS1003_H_
    #define DBG_TAG "pms_series"
    #define DBG_LVL DBG_INFO
    #include
    #include
    #include
    #define COMM_LEN 32
    struct pms_device
    {
    rt_device_t serial;
    struct serial_configure config;
    rt_uint16_t len;
    rt_uint16_t PM1_0_CF1;
    rt_uint16_t PM2_5_CF1;
    rt_uint16_t PM10_0_CF1;
    rt_uint16_t PM1_0_amb;
    rt_uint16_t PM2_5_amb;
    rt_uint16_t PM10_0_amb;
    rt_uint16_t air_0_3um;
    rt_uint16_t air_0_5um;
    rt_uint16_t air_1_0um;
    rt_uint16_t air_2_5um;
    rt_uint16_t air_5_0um;
    rt_uint16_t air_10_0um;
    rt_uint8_t version;
    rt_uint8_t errorCode;
    rt_uint16_t checksum;
    };
    typedef struct pms_device *pms_device_t;
    pms_device_t pms_init(const char *uart_name);
    rt_err_t frame_check(pms_device_t dev,rt_uint8_t buf,rt_uint16_t len);
    rt_err_t pms_get_byte(pms_device_t dev, char data);
    void pms_deinit(pms_device_t dev);
    #endif /
    SRC_PMS1003_H_ /
    /
  • Copyright (c) 2006-2021, RT-Thread Development Team
  • SPDX-License-Identifier: Apache-2.0

Change Logs:
Date Author Notes
2021-10-10 Sherman first version
/
#include
#include "hal_data.h"
#include
#define LED1_PIN "P502" /
Onboard LED pins /
#define DBG_ENABLE
#define DBG_SECTION_NAME "pms_series"
#define DBG_LEVEL DBG_LOG
#define DBG_COLOR
#include
#include
#define PMS_SERIES_UART "uart0"
#define DBG_ENABLE
struct rx_msg
{
rt_device_t dev;
rt_size_t size;
};
#ifdef PMS_SERIES_SAMPLE_USING_DMA
struct rt_messagequeue pms_mq;
#else
struct rt_semaphore pms_sem;
#endif
void pms_series_debug(pms_device_t dev)
{
LOG_D("begin
*");
LOG_D("PM1_0_CF1 = %5dtPM2_5_CF1 = %5dtPM10_0_CF1 = %5d",dev->PM1_0_CF1,dev->PM2_5_CF1,dev->PM10_0_CF1);
LOG_D("PM1_0_amb = %5dtPM2_5_amb = %5dtPM10_0_amb = %5d",dev->PM1_0_amb,dev->PM2_5_amb,dev->PM10_0_amb);
LOG_D("air_0_3um = %5dtair_0_5um = %5dtair_1_0um = %5d",dev->air_0_3um,dev->air_0_5um,dev->air_1_0um);
LOG_D("air_2_5um = %5dt",dev->air_2_5um);
LOG_D("version = %5d errorCode = %5d",dev->version,dev->errorCode);
LOG_D(" over *****");
}
static void serial_thread_entry(void *parameter)
{
#ifndef PMS_SERIES_SAMPLE_USING_DMA
rt_err_t result;
char ch;
pms_device_t dev = parameter;
while (1)
{
while (rt_device_read(dev->serial, 0, &ch, 1) == 0)
{
rt_sem_control(&pms_sem, RT_IPC_CMD_RESET, RT_NULL);
rt_sem_take(&pms_sem, RT_WAITING_FOREVER);
}
result = pms_get_byte(dev,ch);
if (result == RT_EOK)
{
pms_series_debug(dev);
}
}
#endif
#ifdef PMS_SERIES_SAMPLE_USING_DMA
struct rx_msg msg;
rt_err_t result;
rt_uint32_t rx_length;
static rt_uint8_t rx_buffer[RT_SERIAL_RB_BUFSZ + 1];
pms_device_t dev = parameter;
while (1)
{
rt_memset(&msg, 0, sizeof(msg));
result = rt_mq_recv(&pms_mq, &msg, sizeof(msg), RT_WAITING_FOREVER);
if (result == RT_EOK)
{
rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
rx_buffer[rx_length] = '?';
result = frame_check(dev,rx_buffer,rx_length);
if (result == RT_EOK)
{
pms_series_debug(dev);
LOG_D("rx buff success");
}
else
{
LOG_E("rx buff error");
}
}
}
#endif
}
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
RT_ASSERT(dev);
#ifndef PMS_SERIES_SAMPLE_USING_DMA
if (size > 0)
{
rt_sem_release(&pms_sem);
}
return RT_EOK;
#endif
#ifdef PMS_SERIES_SAMPLE_USING_DMA
rt_err_t result;
struct rx_msg msg;
msg.dev = dev;
msg.size = size;
result = rt_mq_send(&pms_mq, &msg, sizeof(msg));
if ( result == -RT_EFULL)
{
rt_kprintf("message queue full!n");
}
return result;
#endif
}
//int pms_sample(int argc, char *argv[])
int pms_sample()
{
static pms_device_t dev = NULL;
rt_err_t ret = RT_EOK;
dev = pms_init(PMS_SERIES_UART);
#ifndef PMS_SERIES_SAMPLE_USING_DMA
rt_sem_init(&pms_sem, "pms_sem", 0, RT_IPC_FLAG_FIFO);
rt_device_open(dev->serial, RT_DEVICE_FLAG_INT_RX);
rt_device_set_rx_indicate(dev->serial, uart_input);
#endif
#ifdef PMS_SERIES_SAMPLE_USING_DMA
static char msg_pool[256];
rt_err_t result;
result = rt_mq_init(&pms_mq, "pms_mq",
msg_pool,
sizeof(struct rx_msg),
sizeof(msg_pool),
RT_IPC_FLAG_FIFO);
if (result != RT_EOK)
{
LOG_E("init message queue failed.n");
}
result = rt_device_open(dev->serial, RT_DEVICE_FLAG_DMA_RX);
if (result != RT_EOK)
{
LOG_E("open device failed.n");
}
result = rt_device_set_rx_indicate(dev->serial, uart_input);
if (result != RT_EOK)
{
LOG_E("set rx indicate failed.n");
}
#endif
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, dev, 1024, 3, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
ret = RT_ERROR;
}
return ret;
}
INIT_APP_EXPORT(pms_sample);
//MSH_CMD_EXPORT(pms_sample, pms_series drive sample);
void hal_entry(void)
{
rt_kprintf("nHello RT-Thread!n");
rt_uint32_t led1_pin = rt_pin_get(LED1_PIN);
while (1)
{
rt_pin_write(led1_pin, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(led1_pin, PIN_LOW);
rt_thread_mdelay(500);
}
}

五、 燒錄驗(yàn)證

1.jpg

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀(guān)點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 傳感器
    +關(guān)注

    關(guān)注

    2541

    文章

    49963

    瀏覽量

    747542
  • 驅(qū)動(dòng)器
    +關(guān)注

    關(guān)注

    51

    文章

    7998

    瀏覽量

    145027
  • SRC
    SRC
    +關(guān)注

    關(guān)注

    0

    文章

    60

    瀏覽量

    17902
  • uart通信
    +關(guān)注

    關(guān)注

    0

    文章

    19

    瀏覽量

    6988
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1239

    瀏覽量

    39441
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    如何在RT-Thread Studio完成對(duì)RA2L1的環(huán)境搭建以及gpio的輸入輸出檢測(cè)?

    有幸參加RT-Thread的活動(dòng),體驗(yàn)RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估。本篇文章主要講解如何在RT-Thread Studio 完成對(duì)RA2L1
    的頭像 發(fā)表于 09-28 15:51 ?2457次閱讀
    如何在RT-Thread Studio完成對(duì)<b class='flag-5'>RA2L1</b><b class='flag-5'>板</b>的環(huán)境搭建以及gpio的輸入輸出檢測(cè)?

    使用RT-Thread和CPK-RA2L1采集DHT11溫濕度

    本篇文章主要介紹使用RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估,使用大佬的輪子采集溫濕度
    的頭像 發(fā)表于 10-11 11:34 ?1465次閱讀
    使用RT-Thread和<b class='flag-5'>CPK-RA2L1</b>采集DHT11溫濕度

    Renesas RA2L1開(kāi)發(fā)之I2C測(cè)評(píng)

    1、Renesas RA2L1開(kāi)發(fā)之I2C  開(kāi)發(fā)介紹  CPK-RA2L1
    發(fā)表于 10-24 16:29

    Renesas RA2L1開(kāi)發(fā)之PWM呼吸燈功能設(shè)計(jì)實(shí)現(xiàn)

    1、Renesas RA2L1開(kāi)發(fā)之PWM呼吸燈功能實(shí)現(xiàn)  CPK-RA2L1評(píng)估  MCU
    發(fā)表于 10-25 14:48

    Renesas RA2L1開(kāi)發(fā)之CAN介紹

    1、Renesas RA2L1開(kāi)發(fā)之CAN介紹  功能模塊的硬件介紹  CPK-RA2L1評(píng)估
    發(fā)表于 11-01 11:46

    Renesas RA2L1開(kāi)發(fā)之I2C接口評(píng)測(cè)

    1、Renesas RA2L1 開(kāi)發(fā)之 I2C  開(kāi)發(fā)介紹  CPK-RA2L1
    發(fā)表于 11-04 14:26

    使用RT-Thread Studio和CPK-RA2L1點(diǎn)亮0.96寸OLED ssd1306

      一、準(zhǔn)備  本篇文章主要介紹使用RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估,使用大佬的輪子來(lái)點(diǎn)亮0.96寸 OLED ssd1306,  二、硬件準(zhǔn)備  首先準(zhǔn)備一個(gè)
    發(fā)表于 04-03 16:14

    基于RT-Thread和CPK-RA2L1制作一個(gè)空氣質(zhì)量監(jiān)測(cè)系統(tǒng)

      一、背景  有幸參加RT-Thread的活動(dòng),體驗(yàn)RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估。本篇結(jié)合前面的文章,暫時(shí)制作一個(gè)空氣質(zhì)量監(jiān)測(cè)系統(tǒng),主要使用:DHT11
    發(fā)表于 04-03 16:36

    如何使用CPK-RA2L1/CPK-RA2E1創(chuàng)建基于FreeRTOS的CapTouch觸摸按鍵demo工程

    CPK-RA2 MCU群組中國(guó)本地評(píng)估 CPK-RA2L1/CPK-RA2E1是用于瑞薩RA2L1
    的頭像 發(fā)表于 11-22 12:20 ?1398次閱讀

    基于RA2L1的串口及J-Link的燒寫(xiě)說(shuō)明

    本節(jié)介紹使用串口工具對(duì)RA2L1進(jìn)行程序的燒寫(xiě)。采用CPK-RA2L1開(kāi)發(fā),硬件如下圖所示。
    的頭像 發(fā)表于 11-25 13:55 ?1574次閱讀

    CPK-RA2L1/RA2E1 評(píng)估入口

    CPK-RA2L1/RA2E1 評(píng)估入口
    發(fā)表于 01-13 19:04 ?4次下載
    <b class='flag-5'>CPK-RA2L1</b>/<b class='flag-5'>RA2E1</b> <b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b>入口

    CPK-RA2L1/RA2E1 評(píng)估入口

    CPK-RA2L1/RA2E1 評(píng)估入口
    發(fā)表于 07-03 19:44 ?0次下載
    <b class='flag-5'>CPK-RA2L1</b>/<b class='flag-5'>RA2E1</b> <b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b>入口

    CPK-RA2L1評(píng)估I2C點(diǎn)亮OLED

    本篇文章主要介紹使用RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估,使用大佬的輪子來(lái)點(diǎn)亮0.96寸 OLED ssd1306,
    發(fā)表于 10-11 10:54 ?344次閱讀
    <b class='flag-5'>CPK-RA2L1</b><b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b>I<b class='flag-5'>2</b>C點(diǎn)亮OLED

    CPK-RA2L1評(píng)估(5)室內(nèi)空氣質(zhì)量監(jiān)測(cè)系統(tǒng)設(shè)計(jì)

    有幸參加RT-Thread的活動(dòng),體驗(yàn)RT-Thread Studio 和瑞薩 CPK-RA2L1評(píng)估。本篇結(jié)合前面的文章,暫時(shí)制作一個(gè)空氣質(zhì)量監(jiān)測(cè)系統(tǒng),主要使用:DHT11、PMS1003
    的頭像 發(fā)表于 10-11 14:30 ?694次閱讀
    <b class='flag-5'>CPK-RA2L1</b><b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b>(5)室內(nèi)空氣質(zhì)量監(jiān)測(cè)系統(tǒng)設(shè)計(jì)

    RTT RA2L1 HS3003采集溫濕度之一

    選擇基于開(kāi)發(fā)->CPK-RA2L1 填入項(xiàng)目名稱(chēng),點(diǎn)擊完成,就創(chuàng)建好了工程。
    的頭像 發(fā)表于 10-12 11:02 ?507次閱讀
    RTT <b class='flag-5'>RA2L1</b> HS3003采集溫濕度之一