chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

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

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

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

RT-Thread CAN驅動

華仔的編程隨筆 ? 來源:華仔的編程隨筆 ? 作者:華仔的編程隨筆 ? 2023-04-21 15:24 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

沁恒CH32x RT-Thread驅動添加適配CH32V208驅動-電子發(fā)燒友網(wǎng) (elecfans.com)

在這個基礎上,我增加了適配CAN的驅動,接著就可以篇寫CAN驅動,來實現(xiàn)數(shù)據(jù)收發(fā)了。

配置

  1. 打開env工具,輸入menuconfig,打開圖形配置界面,選擇Hardware Drivers Conifg---->On-chip Peripheral Drivers-->Enable CAN-->啟動Using CAN1
    image.png
  2. 添加 can測試文件。用vscode打開rtthread目錄添加can_sample.c函數(shù)如下:
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-02-01     Administrator       the first version
 */
/*
 * 程序清單:這是一個 CAN 設備使用例程
 * 例程導出了 can_sample 命令到控制終端
 * 命令調(diào)用格式:can_sample can1
 * 命令解釋:命令第二個參數(shù)是要使用的 CAN 設備名稱,為空則使用默認的 CAN 設備
 * 程序功能:通過 CAN 設備發(fā)送一幀,并創(chuàng)建一個線程接收數(shù)據(jù)然后打印輸出。
*/

#include 
#include "rtdevice.h"

#define CAN_DEV_NAME       "can1"      /* CAN 設備名稱 */
static struct rt_semaphore rx_sem;     /* 用于接收消息的信號量 */
static rt_device_t can_dev;            /* CAN 設備句柄 */
/* 接收數(shù)據(jù)回調(diào)函數(shù) */
static rt_err_t can_rx_call(rt_device_t dev, rt_size_t size)
{
    /* CAN 接收到數(shù)據(jù)后產(chǎn)生中斷,調(diào)用此回調(diào)函數(shù),然后發(fā)送接收信號量 */
    rt_sem_release(&rx_sem);
    
    return RT_EOK;
}

int can_send(rt_uint32_t humi,rt_uint32_t temp)
{
    struct rt_can_msg msg = {0};
    rt_err_t res;
    rt_size_t  size;
    msg.id = 0x78;              /* ID 為 0x78 */
       msg.ide = RT_CAN_STDID;     /* 標準格式 */
       msg.rtr = RT_CAN_DTR;       /* 數(shù)據(jù)幀 */
       msg.len = 8;                /* 數(shù)據(jù)長度為 8 */
       /* 待發(fā)送的 8 字節(jié)數(shù)據(jù) */
       msg.data[0] = (uint8_t)(temp/100);
       msg.data[1] = (uint8_t)(temp%100);
       msg.data[2] = (uint8_t)(humi/100);
       msg.data[3] = (uint8_t)(humi%100);
       msg.data[4] = 0x44;
       msg.data[5] = 0x55;
       msg.data[6] = 0x66;
       msg.data[7] = 0x77;
       /* 發(fā)送一幀 CAN 數(shù)據(jù) */
       size = rt_device_write(can_dev, 0, &msg, sizeof(msg));
       if (size == 0)
       {
           rt_kprintf("can dev write data failed!
");
       }

       return res;
}

static void can_rx_thread(void *parameter)
{
    int i;
    rt_err_t res;
    struct rt_can_msg rxmsg = {0};

    /* 設置接收回調(diào)函數(shù) */
    rt_device_set_rx_indicate(can_dev, can_rx_call);

#ifdef RT_CAN_USING_HDR
    struct rt_can_filter_item items[5] =
    {
        RT_CAN_FILTER_ITEM_INIT(0x100, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x100~0x1ff,hdr 為 - 1,設置默認過濾表 */
        RT_CAN_FILTER_ITEM_INIT(0x300, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x300~0x3ff,hdr 為 - 1 */
        RT_CAN_FILTER_ITEM_INIT(0x211, 0, 0, 0, 0x7ff, RT_NULL, RT_NULL), /* std,match ID:0x211,hdr 為 - 1 */
        RT_CAN_FILTER_STD_INIT(0x486, RT_NULL, RT_NULL),                  /* std,match ID:0x486,hdr 為 - 1 */
        {0x555, 0, 0, 0, 0x7ff, 7,}                                       /* std,match ID:0x555,hdr 為 7,指定設置 7 號過濾表 */
    };
    struct rt_can_filter_config cfg = {5, 1, items}; /* 一共有 5 個過濾表 */
    /* 設置硬件過濾表 */
    res = rt_device_control(can_dev, RT_CAN_CMD_SET_FILTER, &cfg);
    RT_ASSERT(res == RT_EOK);
#endif

    while (1)
    {
        /* hdr 值為 - 1,表示直接從 uselist 鏈表讀取數(shù)據(jù) */
        rxmsg.hdr_index = -1;
        /* 阻塞等待接收信號量 */
        rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
        /* 從 CAN 讀取一幀數(shù)據(jù) */
        rt_device_read(can_dev, 0, &rxmsg, sizeof(rxmsg));
        /* 打印數(shù)據(jù) ID 及內(nèi)容 */
        rt_kprintf("ID:%x", rxmsg.id);
        for (i = 0; i < 8; i++)
        {
            rt_kprintf("%2x", rxmsg.data[i]);
        }
        rt_kprintf("recv end
");
    }
}

int can_sample(void)
{
    struct rt_can_msg msg = {0};
    rt_err_t res;
    rt_size_t  size;
    rt_thread_t thread;
    char can_name[RT_NAME_MAX];

    rt_strncpy(can_name, CAN_DEV_NAME, RT_NAME_MAX);

    /* 查找 CAN 設備 */
    can_dev = rt_device_find(can_name);
    if (!can_dev)
    {
        rt_kprintf("find %s failed!
", can_name);
        return RT_ERROR;
    }

    /* 初始化 CAN 接收信號量 */
    rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
    /* 設置 CAN 通信的波特率為 500kbit/s*/
    res = rt_device_control(can_dev, RT_CAN_CMD_SET_BAUD, (void *)CAN500kBaud);
    /* 以中斷接收及發(fā)送方式打開 CAN 設備 */
    res = rt_device_open(can_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);

    RT_ASSERT(res == RT_EOK);
    /* 創(chuàng)建數(shù)據(jù)接收線程 */
    thread = rt_thread_create("can_rx", can_rx_thread, RT_NULL, 2056, 25, 10);
    if (thread != RT_NULL)
    {
        rt_thread_startup(thread);
    }
    else
    {
        rt_kprintf("create can_rx thread failed!
");
    }

    msg.id = 0x78;              /* ID 為 0x78 */
    msg.ide = RT_CAN_STDID;     /* 標準格式 */
    msg.rtr = RT_CAN_DTR;       /* 數(shù)據(jù)幀 */
    msg.len = 8;                /* 數(shù)據(jù)長度為 8 */
    /* 待發(fā)送的 8 字節(jié)數(shù)據(jù) */
    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;
    /* 發(fā)送一幀 CAN 數(shù)據(jù) */
    size = rt_device_write(can_dev, 0, &msg, sizeof(msg));
    if (size == 0)
    {
        rt_kprintf("can dev write data failed!
");
    }

    rt_kprintf("can dev write data OK !
");
    return res;
}
/* 導出到 msh 命令列表中 */
MSH_CMD_EXPORT(can_sample, can device sample);
  1. 在env工具中輸入scons執(zhí)行編譯:

image.png

  1. 然后打開wchisp工具把rtthread.bin下載到開發(fā)板:
    image.png
  2. 用CAN轉TTL連接到CAN分析儀上,打開調(diào)試軟件,以及msh終端:
    image.png

image.png

【總結】

雖然wch在rtthread的驅動沒有更新,但是經(jīng)過我的修復,順利的完成CAN的測試工作。

審核編輯:湯梓紅

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

    關注

    59

    文章

    3044

    瀏覽量

    472145
  • 開發(fā)板
    +關注

    關注

    26

    文章

    6213

    瀏覽量

    116016
  • RTT
    RTT
    +關注

    關注

    0

    文章

    66

    瀏覽量

    18211
  • RT-Thread
    +關注

    關注

    32

    文章

    1583

    瀏覽量

    44515
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    RT-ThreadCAN實踐

    開箱測試RT-Thread官方已完成了對英飛凌XMC7200EVK的移植,通過shell可以看到做好了uart3的console。本文將介紹如何進行RT-ThreadCan移植。接下來我們要完成CAN_FD的
    的頭像 發(fā)表于 11-13 01:03 ?3021次閱讀
    <b class='flag-5'>RT-Thread</b>上<b class='flag-5'>CAN</b>實踐

    RT-Thread NUC97x 移植 LVGL

    不涉及 rt-thread 驅動,但是它是 LVGL 和 rt-thread 的接口。LVGL 在 rt-thread 上運行的基石。
    發(fā)表于 07-08 09:37 ?2060次閱讀

    RT-Thread ssd1306驅動

    RT-Thread 驅動ssd1306
    的頭像 發(fā)表于 04-21 10:08 ?26.6w次閱讀
    <b class='flag-5'>RT-Thread</b> ssd1306<b class='flag-5'>驅動</b>

    基于RT-Thread CAN驅動框架實現(xiàn)開發(fā)板和CAN調(diào)試器進行CAN通信驗證

    1、基于rt-thread CAN驅動框架通信評測步驟  本章通過ENV環(huán)境配置M2354片上外設CAN的功能,Keil Arm編譯,基于rt-th
    發(fā)表于 11-15 16:27

    RT-Thread編程指南

    RT-Thread編程指南——RT-Thread開發(fā)組(2015-03-31)。RT-Thread做為國內(nèi)有較大影響力的開源實時操作系統(tǒng),本文是RT-Thread實時操作系統(tǒng)的編程指南
    發(fā)表于 11-26 16:06 ?0次下載

    RT-Thread上的CAN總線介紹以及驅動編寫

    昨晚很榮幸邀請到李工在RT-Thread微信群進行RT-Thread上的CAN驅動和應用講座。小編整理了講座內(nèi)容,特發(fā)出講義以供享用。
    的頭像 發(fā)表于 09-25 10:16 ?2.5w次閱讀

    RT-Thread Studio驅動SD卡

    RT-Thread Studio驅動SD卡前言一、創(chuàng)建基本工程1、創(chuàng)建Bootloader2、創(chuàng)建項目工程二、配置RT-Thread Settings三、代碼分析1.引入庫2.讀入數(shù)據(jù)四、效果驗證
    發(fā)表于 12-27 19:13 ?20次下載
    <b class='flag-5'>RT-Thread</b> Studio<b class='flag-5'>驅動</b>SD卡

    RT-Thread開源作品秀】基于RT-Thread的星務平臺研究

    本作品為了驗證星務軟件在RT-Thread系統(tǒng)運行的可行性,底層是否能夠驅動星務軟件,同時擴展RT-Thread應用范圍。ART-Pi作為衛(wèi)星下位機,...
    發(fā)表于 01-25 18:26 ?6次下載
    【<b class='flag-5'>RT-Thread</b>開源作品秀】基于<b class='flag-5'>RT-Thread</b>的星務平臺研究

    RT-Thread學習筆記 RT-Thread的架構概述

    RT-Thread 簡介 作為一名 RTOS 的初學者,也許你對 RT-Thread 還比較陌生。然而,隨著你的深入接觸,你會逐漸發(fā)現(xiàn) RT-Thread 的魅力和它相較于其他同類型 RTOS
    的頭像 發(fā)表于 07-09 11:27 ?5698次閱讀
    <b class='flag-5'>RT-Thread</b>學習筆記 <b class='flag-5'>RT-Thread</b>的架構概述

    RT-Thread文檔_RT-Thread 簡介

    RT-Thread文檔_RT-Thread 簡介
    發(fā)表于 02-22 18:22 ?5次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> 簡介

    RT-Thread文檔_RT-Thread 潘多拉 STM32L475 上手指南

    RT-Thread文檔_RT-Thread 潘多拉 STM32L475 上手指南
    發(fā)表于 02-22 18:23 ?10次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> 潘多拉 STM32L475 上手指南

    RT-Thread文檔_RT-Thread SMP 介紹與移植

    RT-Thread文檔_RT-Thread SMP 介紹與移植
    發(fā)表于 02-22 18:31 ?9次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>RT-Thread</b> SMP 介紹與移植

    RT-Thread文檔_CAN 設備

    RT-Thread文檔_CAN 設備
    發(fā)表于 02-22 18:34 ?0次下載
    <b class='flag-5'>RT-Thread</b>文檔_<b class='flag-5'>CAN</b> 設備

    基于RT-ThreadCAN電機驅動板設計(一)需求分析與硬件設計

    本項目依托實驗室機器人比賽,需要設計一個電機驅動板,控制8個CAN協(xié)議的伺服電機。為了鍛煉我對RT-Thread的使用能力同時加快開發(fā)進度,減少花費在驅動代碼上的時間,電機
    發(fā)表于 03-17 13:53 ?1次下載
    基于<b class='flag-5'>RT-Thread</b>的<b class='flag-5'>CAN</b>電機<b class='flag-5'>驅動</b>板設計(一)需求分析與硬件設計

    基于RT-Thread Studio學習

    前期準備:從官網(wǎng)下載 RT-Thread Studio,弄個賬號登陸,開啟rt-thread學習之旅。
    的頭像 發(fā)表于 05-15 11:00 ?6222次閱讀
    基于<b class='flag-5'>RT-Thread</b> Studio學習