首頁(yè) > 評(píng)測(cè) > 【AutoChips 7801x MCU評(píng)測(cè)報(bào)告】+串口nr_micro_shell移植測(cè)試
【AutoChips 7801x MCU評(píng)測(cè)報(bào)告】+串口nr_micro_shell移植測(cè)試
- [導(dǎo)讀]
- 移植了一個(gè)串口shell程序nr_micro_shell。順便測(cè)試了I2C接口的讀寫(xiě)AT24Cxx。移植很簡(jiǎn)單,主要在nr_micro_shell_config.h文件內(nèi)配置,以及串口發(fā)送接收函數(shù)。主函數(shù)main內(nèi)初始化
移植了一個(gè)串口shell程序nr_micro_shell。順便測(cè)試了I2C接口的讀寫(xiě)AT24Cxx。移植很簡(jiǎn)單,主要在nr_micro_shell_config.h文件內(nèi)配置,以及串口發(fā)送接收函數(shù)。主函數(shù)main內(nèi)初始化和接收串口數(shù)據(jù)處理。
代碼如下:
- /*************<include>****************/
- #include "string.h"
- #include "ac780x.h"
- #include "system_ac780x.h"
- #include "ac780x_gpio.h"
- #include "ac780x_uart.h"
- #include "elog.h"
- #include "nr_micro_shell.h"
- #include "i2c.h"
- /*************<macro>******************/
- #define LED2_PORT (GPIOC)
- #define LED2_PIN (GPIO_PIN9)
- #define LED3_PORT (GPIOC)
- #define LED3_PIN (GPIO_PIN7)
- #define LED2_ON() do{GPIO_SetPinLevel(LED2_PORT, LED2_PIN, GPIO_LEVEL_HIGH);}while(0)
- #define LED2_OFF() do{GPIO_SetPinLevel(LED2_PORT, LED2_PIN, GPIO_LEVEL_LOW);}while(0)
- #define LED2_TOGGLE() do{if(GPIO_GetPinLevel(LED2_PORT, LED2_PIN)){LED2_OFF;}else{LED2_ON;}}while(0)
- #define LED3_ON() do{GPIO_SetPinLevel(LED3_PORT, LED3_PIN, GPIO_LEVEL_HIGH);}while(0)
- #define LED3_OFF() do{GPIO_SetPinLevel(LED3_PORT, LED3_PIN, GPIO_LEVEL_LOW);}while(0)
- #define LED3_TOGGLE() do{if(GPIO_GetPinLevel(LED3_PORT, LED3_PIN)){LED3_OFF;}else{LED3_ON;}}while(0)
- /*************<enum>*******************/
- /*************<union>******************/
- /*************<struct>*****************/
- /*************<variable>***************/
- /*************<prototype>**************/
- void shell_ls_cmd(char argc, char *argv)
- {
- unsigned int i = 0;
- if (argc > 1)
- {
- if (!strcmp("cmd", &argv[argv[1]]))
- {
- for (i = 0; nr_shell.static_cmd[i].fp != NULL; i++)
- {
- shell_printf(nr_shell.static_cmd[i].cmd);
- shell_printf("\r\n");
- }
- }
- else if (!strcmp("-v", &argv[argv[1]]))
- {
- shell_printf("ls version 1.0.\r\n");
- }
- else if (!strcmp("-h", &argv[argv[1]]))
- {
- shell_printf("useage: ls [options]\r\n");
- shell_printf("options: \r\n");
- shell_printf("\t -h \t: show help\r\n");
- shell_printf("\t -v \t: show version\r\n");
- shell_printf("\t cmd \t: show all commands\r\n");
- }
- }
- else
- {
- shell_printf("ls need more arguments!\r\n");
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] test command
- */
- void shell_test_cmd(char argc, char *argv)
- {
- unsigned int i;
- shell_printf("test command:\r\n");
- for (i = 0; i < argc; i++)
- {
- shell_printf("paras %d: %s\r\n", i, &(argv[argv[i]]));
- }
- }
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] test command
- */
- void shell_led_cmd(char argc, char *argv)
- {
- if (argc > 1)
- {
- if (!strcmp("on", &argv[argv[1]]))
- {
- if (!strcmp("1", &argv[argv[2]]))
- {
- LED2_ON();
- }else if (!strcmp("2", &argv[argv[2]]))
- {
- LED3_ON();
- }else
- {
- shell_printf("useage: led [on/off] [1/2/3/4]\r\n");
- }
- }else if (!strcmp("off", &argv[argv[1]]))
- {
- if (!strcmp("1", &argv[argv[2]]))
- {
- LED2_OFF();
- }else if (!strcmp("2", &argv[argv[2]]))
- {
- LED3_OFF();
- }else
- {
- shell_printf("useage: led [on/off] [1/2/3/4]\r\n");
- }
- }else{
- shell_printf("useage: led [on/off] [1/2/3/4]\r\n");
- }
- }
- }
- void at24cxx_cmd(char argc, char *argv)
- {
- if (argc > 1)
- {
- if (!strcmp("read", &argv[argv[1]]))
- {
- I2C_RdDataFromAT24C();
- }else if (!strcmp("write", &argv[argv[1]]))
- {
- I2C_WrDataToAT24C();
- }else{
- shell_printf("useage: at24 [read/write] \r\n");
- }
- }else{
- shell_printf("useage: at24 [read/write] \r\n");
- }
- }
- NR_SHELL_CMD_EXPORT(at24, at24cxx_cmd);
- #ifdef NR_SHELL_USING_EXPORT_CMD
- NR_SHELL_CMD_EXPORT(ls, shell_ls_cmd);
- NR_SHELL_CMD_EXPORT(test, shell_test_cmd);
- NR_SHELL_CMD_EXPORT(led, shell_led_cmd);
- #else
- const static_cmd_st static_cmd[] =
- {
- {"ls", shell_ls_cmd},
- {"test", shell_test_cmd},
- {"led", shell_led_cmd},
- {"\0", NULL}
- };
- #endif
- /**
- * [url=home.php?mod=space&uid=555622]@prototype[/url] main(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief main entry.
- * main.
- */
- int main(void)
- {
- uint8_t ch;
- InitDelay(); //sysclk Delay
- InitDebug(); //Uart Debug printf
- //èLEDGPIO.
- GPIO_SetDir(LED2_PORT, LED2_PIN, GPIO_OUT);
- GPIO_SetDir(LED3_PORT, LED3_PIN, GPIO_OUT);
- I2C_InitHw();
- elog_init();
- shell_init(); /* nr_micro_shell*/
- while(1)
- {
- if (UART_RxIsDataReady(UART2))
- {br />
- ch = UART_ReceiveData(UART2);
- shell(ch);
- }
- }
- }
- /*************<end>********************/
I2C程序:
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("AutoChips Software") are
- * protected under relevant copyright laws. The information contained herein is
- * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
- * the prior written permission of AutoChips inc. and/or its licensors, any
- * reproduction, modification, use or disclosure of AutoChips Software, and
- * information contained herein, in whole or in part, shall be strictly
- * prohibited.
- *
- * AutoChips Inc. (C) 2018. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
- * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
- * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
- * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
- * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
- * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
- * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
- * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
- * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
- * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
- * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
- * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
- * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
- * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
- * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
- */
- /*************<start>******************/
- /*************<include>****************/
- #include "i2c.h"
- /*************<macro>******************/
- #define AT24C02_DEV_ADDR (0x50)
- /*************<enum>*******************/
- /*************<union>******************/
- /*************<struct>*****************/
- /*************<variable>***************/
- uint8_t g_wrAT24CDataBuf[9];
- uint8_t g_rdAT24CDataBuf[9];
- /*************<prototype>**************/
- /**
- * @prototype I2C_InitHw(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief I2C.
- */
- void I2C_InitHw(void)
- {
- I2C_ConfigType i2cConfig = {0};
- /*I2C.*/
- GPIO_SetFunc(I2C0_SCL_PORT, I2C0_SCL_PIN, GPIO_FUN3);
- GPIO_SetFunc(I2C0_SDA_PORT, I2C0_SDA_PIN, GPIO_FUN3);
- /*I2Cè.*/
- i2cConfig.masterConfigs.ARBEn = ENABLE;/*è÷ú.*/
- i2cConfig.masterConfigs.SYNCEn = ENABLE;/*è÷úSCL.*/
- /*è¨100Kbps,bandrate = 24M / (10 * 12 * 2) = 100Kbps;*/
- i2cConfig.masterConfigs.sampleCnt = 9;
- i2cConfig.masterConfigs.stepCnt = 11;
- i2cConfig.slaveConfigs.addExtEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.addRangeEn = DISABLE;/*§.*/
- i2cConfig.slaveConfigs.monitorEn = DISABLE;/*úà.*/
- i2cConfig.slaveConfigs.stretchEn = DISABLE;/*úSCLì.*/
- i2cConfig.slaveConfigs.gcaEn = DISABLE;/*úSCL.*/
- i2cConfig.slaveConfigs.wakeupEn = DISABLE;/*,ú±§.*/
- i2cConfig.slaveConfigs.RXFInterruptEn = DISABLE;/*ú.*/
- i2cConfig.slaveConfigs.RXOFInterruptEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.TXEInterruptEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.TXUFInterruptEn = DISABLE;/*.*/
- i2cConfig.slaveConfigs.slaveAddress = AT24C02_DEV_ADDR;/*ú.*/
- i2cConfig.slaveConfigs.slave7BitRangeAddress = 0;/*ú§.*/
- i2cConfig.glitchFilterCnt = 0;/*.*/
- i2cConfig.interruptEn = DISABLE;/*I2C.*/
- i2cConfig.nackInterruptEn = DISABLE;/*NACK.*/
- i2cConfig.ssInterruptEn = DISABLE;/*×startòstop.*/
- i2cConfig.dmaRxEn = DISABLE;/*èDMA.*/
- i2cConfig.dmaTxEn = DISABLE;/*èDMA.*/
- i2cConfig.mode = I2C_MASTER;/*è÷ú.*/
- i2cConfig.i2cEn &bsp; = ENABLE;/*é.*/
- i2cConfig.callBack = NULL;/*÷.*/
- I2C_Init(I2C0, &i2cConfig);
- }
- /**
- * @prototype I2C_WrDataToAT24C(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief EEPROM.
- */
- void I2C_WrDataToAT24C(void)
- {
- g_wrAT24CDataBuf[0] = 0x00;//
- for (uint8_t ii = 0; ii < 8; ii++)
- {
- g_wrAT24CDataBuf[ii + 1] = ii+10;
- printf("%02X ", g_wrAT24CDataBuf[ii + 1]);
- }printf("\r\n");
- I2C_MasterBurstWrite(I2C0, AT24C02_DEV_ADDR, g_wrAT24CDataBuf, 9, ENABLE);
- }
- /**
- * @prototype I2C_RdDataFromAT24C(void)
- *
- * @param[in] void
- * @return void
- *
- * @brief EEPROM.
- */
- void I2C_RdDataFromAT24C(void)
- {
- g_wrAT24CDataBuf[0] = 0x00;//
- I2C_MasterBurstWrite(I2C0, AT24C02_DEV_ADDR, g_wrAT24CDataBuf, 1, DISABLE);
- I2C_MasterBurstRead (I2C0, AT24C02_DEV_ADDR, g_rdAT24CDataBuf, 8);
- for (uint8_t ii = 0; ii < 8; ii++)
- {
- printf("%02X ", g_rdAT24CDataBuf[ii]);
- }
- printf("\r\n");
- }
- /*************<end>********************/
工程代碼:
游客,如果您要查看本帖隱藏內(nèi)容請(qǐng)前往:https://bbs.21ic.com/icview-2972192-1-1.html 查看
- 本文系21ic原創(chuàng),未經(jīng)許可禁止轉(zhuǎn)載!
網(wǎng)友評(píng)論
- 聯(lián)系人:巧克力娃娃
- 郵箱:board@21ic.com
- 我要投稿
-
歡迎入駐,開(kāi)放投稿
行業(yè)新聞
熱門(mén)標(biāo)簽
論壇活動(dòng)
more+
公開(kāi)課
more+
項(xiàng)目外包
more+
- NRF52810藍(lán)牙數(shù)字耳機(jī)找人定制
預(yù)算:¥30005天前
- 125KW模塊式PCS軟硬件外包開(kāi)發(fā)
預(yù)算:¥1100000015小時(shí)前
- 12V汽車(chē)啟動(dòng)電源項(xiàng)目BMS設(shè)計(jì)
預(yù)算:¥50000023小時(shí)前
- 數(shù)據(jù)可視化軟件 開(kāi)發(fā)
預(yù)算:¥5000023小時(shí)前
- PLC項(xiàng)目調(diào)試修改
預(yù)算:¥100001天前
- 起動(dòng)電機(jī)控制器開(kāi)發(fā)
預(yù)算:¥1100001天前