流行科技 发表于 2022-5-22 21:33

瑞萨CPK-RA6M4 开发板测评+DAC输出正弦波

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">拿到开发板一段时间了,断续开始学习RTT,目前先做了下简单的外设功能,已经适配了的外设,我选择使用DAC输出正弦波测试。下面就看下我怎么添加的。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">首先还是需要在工程中找到RA Smart工具配置外设引脚功能。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">新建一个DAC外设。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">这里进去就选择模拟设备,然后选择DAC即可。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">进去后需要配置输出的管脚,跟着箭头就能完成配置。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">之后记得生成下。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">之后配置RTT,使能DAC即可。然后就可以点击构建项目,就能生成代码了。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">生成了一个dac.c的文件,之后我们进去之前的main函数中修改。修改方式就按照dac.c中的一个初始化函数来即可。</span></span></p>

<pre>
<code>#define DAC_DEV_NAME "dac0"

#define DAC_DEV_CHANNEL 0



static rt_dac_device_t dac_device = RT_NULL;





//设置了个数组存放正弦波的数据

const uint16_t Sine12bit2 = {

                      2048,2073,2099,2125,2150,2176,2202,2227,2253,2279,2304,2330,2355,2380,

2406,2431,2456,2482,2507,2532,2557,2582,2606,2631,2656,2680,2705,2729,2753,

2777,2801,2825,2849,2872,2896,2919,2942,2966,2988,3011,3034,3056,3079,3101,

3123,3145,3166,3188,3209,3230,3251,3272,3292,3313,3333,3353,3372,3392,3411,

3430,3449,3468,3486,3504,3522,3540,3558,3575,3592,3609,3625,3641,3657,3673,

3689,3704,3719,3734,3748,3762,3776,3790,3803,3816,3829,3842,3854,3866,3878,

3889,3900,3911,3921,3932,3942,3951,3961,3970,3978,3987,3995,4003,4010,4017,

4024,4031,4037,4043,4048,4054,4059,4063,4068,4072,4075,4079,4082,4085,4087,

4089,4091,4092,4094,4094,4095,4095,4095,4094,4094,4092,4091,4089,4087,4085,

4082,4079,4075,4072,4068,4063,4059,4054,4048,4043,4037,4031,4024,4017,4010,

4003,3995,3987,3978,3970,3961,3951,3942,3932,3921,3911,3900,3889,3878,3866,

3854,3842,3829,3816,3803,3790,3776,3762,3748,3734,3719,3704,3689,3673,3657,

3641,3625,3609,3592,3575,3558,3540,3522,3504,3486,3468,3449,3430,3411,3392,

3372,3353,3333,3313,3292,3272,3251,3230,3209,3188,3166,3145,3123,3101,3079,

3056,3034,3011,2988,2966,2943,2919,2896,2872,2849,2825,2801,2777,2753,2729,

2705,2680,2656,2631,2606,2582,2557,2532,2507,2482,2456,2431,2406,2381,2355,

2330,2304,2279,2253,2227,2202,2176,2150,2125,2099,2073,2048,2022,1996,1970,

1945,1919,1893,1868,1842,1816,1791,1765,1740,1715,1689,1664,1639,1613,1588,

1563,1538,1513,1489,1464,1439,1415,1390,1366,1342,1318,1294,1270,1246,1223,

1199,1176,1153,1129,1107,1084,1061,1039,1016,994,972,950,929,907,886,865,

844,823,803,782,762,742,723,703,684,665,646,627,609,591,573,555,537,520,

503,486,470,454,438,422,406,391,376,361,347,333,319,305,292,279,266,253,

241,229,217,206,195,184,174,163,153,144,134,125,117,108,100,92,85,78,71,

64,58,52,47,41,36,32,27,23,20,16,13,10,8,6,4,3,1,1,0,0,0,1,1,3,4,6,8,10,

13,16,20,23,27,32,36,41,47,52,58,64,71,78,85,92,100,108,117,125,134,144,

153,163,174,184,195,206,217,229,241,253,266,279,292,305,319,333,347,361,

376,391,406,422,438,454,470,486,503,520,537,555,573,591,609,627,646,665,

684,703,723,742,762,782,803,823,844,865,886,907,929,950,972,994,1016,1039,

1061,1084,1107,1129,1153,1176,1199,1223,1246,1270,1294,1318,1342,1366,1390,

1415,1439,1464,1489,1513,1538,1563,1588,1613,1639,1664,1689,1715,1740,1765,

1791,1816,1842,1868,1893,1919,1945,1970,1996,2022};





void hal_entry(void)

{

    rt_kprintf("\nHello RT-Thread!\n");

    static int i = 0;



    dac_device = (rt_dac_device_t )rt_device_find(DAC_DEV_NAME);

   if (dac_device == RT_NULL)

   {

       rt_kprintf("dac sample run failed! can't find %s device!\n", DAC_DEV_NAME);

   }



   rt_dac_enable(dac_device, DAC_DEV_CHANNEL);







    while (1)

    {

//        rt_pin_write(LED3_PIN, PIN_HIGH);

//        rt_thread_mdelay(500);

//        rt_pin_write(LED3_PIN, PIN_LOW);

//        rt_thread_mdelay(1);

        i++;

        if(i&gt;500)

        {

            i = 0;

        }

        rt_dac_write(dac_device,0,Sine12bit2);

        rt_kprintf("I:%d",i);

    }

}</code></pre>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">这里贴下主要代码。主要就是需要初始化外设,然后在调用写值即可,开始调试可以写固定值看有没有输出。综上,开始调试RTT,使用其组件还是很快就能完成任务的。下面看下效果。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">同时其也支持串口命令,输入dac即可看到全部命令。也很方便调试功能。</span></span></p>

<p style="text-align:justify">&nbsp;</p>

<div id="qb-sougou-search" style="display: none; opacity: 0; left: 10px; top: 44.8571px;">
<p>搜索</p>

<p class="last-btn">复制</p>
<iframe src=""></iframe>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><b><span style="background:white"><span style="font-family:&quot;微软雅黑&quot;,sans-serif"><span style="color:#333333">瑞萨CPK-RA6M4 开发板测评+DAC输出正弦波</span></span></span></b></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">拿到开发板一段时间了,断续开始学习RTT,目前先做了下简单的外设功能,已经适配了的外设,我选择使用DAC输出正弦波测试。下面就看下我怎么添加的。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">首先还是需要在工程中找到RA Smart工具配置外设引脚功能。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">新建一个DAC外设。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">这里进去就选择模拟设备,然后选择DAC即可。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">进去后需要配置输出的管脚,跟着箭头就能完成配置。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">之后记得生成下。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">之后配置RTT,使能DAC即可。然后就可以点击构建项目,就能生成代码了。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">生成了一个dac.c的文件,之后我们进去之前的main函数中修改。修改方式就按照dac.c中的一个初始化函数来即可。</span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">#define</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> DAC_DEV_NAME </span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#2a00ff">&quot;dac0&quot;</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">#define</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> DAC_DEV_CHANNEL 0</span></span></span></span></span></span></p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">static</span></span></span></b> <span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#005032">rt_dac_device_t</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> dac_device = RT_NULL;</span></span></span></span></span></span></p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#3f7f5f">//</span></span></span><span style="font-size:11.0pt"><span style="color:#3f7f5f">设置了个数组存放正弦波的数据</span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">const</span></span></span></b> <span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#005032">uint16_t</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> Sine12bit2 = {</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2048,2073,2099,2125,2150,2176,2202,2227,2253,2279,2304,2330,2355,2380,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">2406,2431,2456,2482,2507,2532,2557,2582,2606,2631,2656,2680,2705,2729,2753,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">2777,2801,2825,2849,2872,2896,2919,2942,2966,2988,3011,3034,3056,3079,3101,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3123,3145,3166,3188,3209,3230,3251,3272,3292,3313,3333,3353,3372,3392,3411,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3430,3449,3468,3486,3504,3522,3540,3558,3575,3592,3609,3625,3641,3657,3673,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3689,3704,3719,3734,3748,3762,3776,3790,3803,3816,3829,3842,3854,3866,3878,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3889,3900,3911,3921,3932,3942,3951,3961,3970,3978,3987,3995,4003,4010,4017,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">4024,4031,4037,4043,4048,4054,4059,4063,4068,4072,4075,4079,4082,4085,4087,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">4089,4091,4092,4094,4094,4095,4095,4095,4094,4094,4092,4091,4089,4087,4085,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">4082,4079,4075,4072,4068,4063,4059,4054,4048,4043,4037,4031,4024,4017,4010,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">4003,3995,3987,3978,3970,3961,3951,3942,3932,3921,3911,3900,3889,3878,3866,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3854,3842,3829,3816,3803,3790,3776,3762,3748,3734,3719,3704,3689,3673,3657,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3641,3625,3609,3592,3575,3558,3540,3522,3504,3486,3468,3449,3430,3411,3392,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3372,3353,3333,3313,3292,3272,3251,3230,3209,3188,3166,3145,3123,3101,3079,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">3056,3034,3011,2988,2966,2943,2919,2896,2872,2849,2825,2801,2777,2753,2729,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">2705,2680,2656,2631,2606,2582,2557,2532,2507,2482,2456,2431,2406,2381,2355,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">2330,2304,2279,2253,2227,2202,2176,2150,2125,2099,2073,2048,2022,1996,1970,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">1945,1919,1893,1868,1842,1816,1791,1765,1740,1715,1689,1664,1639,1613,1588,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">1563,1538,1513,1489,1464,1439,1415,1390,1366,1342,1318,1294,1270,1246,1223,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">1199,1176,1153,1129,1107,1084,1061,1039,1016,994,972,950,929,907,886,865,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">844,823,803,782,762,742,723,703,684,665,646,627,609,591,573,555,537,520,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">503,486,470,454,438,422,406,391,376,361,347,333,319,305,292,279,266,253,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">241,229,217,206,195,184,174,163,153,144,134,125,117,108,100,92,85,78,71,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">64,58,52,47,41,36,32,27,23,20,16,13,10,8,6,4,3,1,1,0,0,0,1,1,3,4,6,8,10,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">13,16,20,23,27,32,36,41,47,52,58,64,71,78,85,92,100,108,117,125,134,144,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">153,163,174,184,195,206,217,229,241,253,266,279,292,305,319,333,347,361,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">376,391,406,422,438,454,470,486,503,520,537,555,573,591,609,627,646,665,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">684,703,723,742,762,782,803,823,844,865,886,907,929,950,972,994,1016,1039,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">1061,1084,1107,1129,1153,1176,1199,1223,1246,1270,1294,1318,1342,1366,1390,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">1415,1439,1464,1489,1513,1538,1563,1588,1613,1639,1664,1689,1715,1740,1765,</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">1791,1816,1842,1868,1893,1919,1945,1970,1996,2022};</span></span></span></span></span></span></p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">void</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> <b>hal_entry</b>(</span></span></span><b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">void</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">)</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">{</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp; rt_kprintf(</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#2a00ff">&quot;\nHello RT-Thread!\n&quot;</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线">&nbsp;&nbsp;&nbsp; <b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">static</span></span></span></b> <b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">int</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> i = 0;</span></span></span></span></span></span></p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp; dac_device = (</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#005032">rt_dac_device_t</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> )rt_device_find(DAC_DEV_NAME);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线">&nbsp;&nbsp; <b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">if</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> (dac_device == RT_NULL)</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp; {</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_kprintf(</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#2a00ff">&quot;<u>dac</u> sample run failed! can&#39;t find %s device!\n&quot;</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">, DAC_DEV_NAME);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp; }</span></span></span></span></span></span></p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp; rt_dac_enable(dac_device, DAC_DEV_CHANNEL);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线">&nbsp;&nbsp;&nbsp; <b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">while</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black"> (1)</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp; {</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#3f7f5f">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_pin_write(LED3_PIN, PIN_HIGH);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#3f7f5f">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_thread_mdelay(500);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#3f7f5f">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_pin_write(LED3_PIN, PIN_LOW);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#3f7f5f">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_thread_mdelay(1);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i++;</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#7f0055">if</span></span></span></b><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">(i&gt;500)</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = 0;</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_dac_write(dac_device,0,Sine12bit2);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt_kprintf(</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:#2a00ff">&quot;I:%d&quot;</span></span></span><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">,i);</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp;&nbsp;&nbsp; }</span></span></span></span></span></span></p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:等线"><span lang="EN-US" style="font-size:11.0pt"><span style="font-family:Consolas"><span style="color:black">}</span></span></span></span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">这里贴下主要代码。主要就是需要初始化外设,然后在调用写值即可,开始调试可以写固定值看有没有输出。综上,开始调试RTT,使用其组件还是很快就能完成任务的。下面看下效果。</span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">同时其也支持串口命令,输入dac即可看到全部命令。也很方便调试功能。</span></span></p>

<p style="text-align:justify">&nbsp;</p>
</div>

<p>&nbsp;</p>

lugl4313820 发表于 2022-5-23 19:45

示波器不错呀,看来楼主是大佬,作品很精彩!
页: [1]
查看完整版本: 瑞萨CPK-RA6M4 开发板测评+DAC输出正弦波