首页 > 评测 > 带你一起玩转WPI基于灵动MM32F0140 Arduino平台方案开发板
带你一起玩转WPI基于灵动MM32F0140 Arduino平台方案开发板
- [导读]
- 相遇疫情期间,无意中在大大通平台上看到了大联大世平集团推出的基于灵动微MM32F0140 MCU制作的Arduino平台方案,在直播中了解到MM32F0410系列MCU功能特性,以及WPI详细介绍了开发的设
- Arm Cortex-M0内核,运行频率高达72MHz
- 最高64KB FLASH和8KB SRAM
- 内置5个DMA通道
- 内置32-bit硬件除法单元
- 3组UART、2组SPI、2组I2C、1组I2C
- 1组FlexCAN,支持CAN2.0协议
- 1组高级定时器,可输出4通道带互补的PWM波形,支持死区和刹车功能
- 1组32-bit定时器、4组16-bit定时器
- 1组12-bit SAR ADC,最高支持1Msps采样率和13路采样通道
- 1组高速模拟比较单元
- 2.0V~5.5V宽工作电压
- 实现ADC采样
- 实现按键检测
- 实现FlexCAN通讯
- 实现EEPROM数据存取功能
- 实现DAC音频播放功能
- 实现IrDA红外通讯功能
- 实现LCD TFT液晶屏幕显示
- 实现NSHT35温湿检测功能
- 实现RGB LED控制功能
- 实现SWITCH开关状态检测功能
- 实现ToF高精度测距功能
- 实现SPI FLASH数据存取功能
- 实现Xmodem下载文件/数据到SPI FLASH的应用功能
- void RGBLED_Toggle(void)
- {
- static uint8_t Step = 0;
- switch(Step)
- {
- case 0:
- GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_RESET);
- GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_SET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
- break;
- case 1:
- GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
- GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_RESET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
- break;
- case 2:
- GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
- GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_SET);
- GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_RESET);
- break;
- default:
- break;
- }
- Step = (Step + 1) % 3;
- }
- void BUTTON_SubScan(uint8_t *State, uint8_t *Count, uint8_t Value, char *Name)
- {
- if(*State == 0)
- {
- if(Value == Bit_RESET) *Count += 1;
- else *Count = 0;
- if(*Count > 5)
- {
- *Count = 0; *State = 1;
- printf("\r\n%s Pressed", Name);
- }
- }
- else
- {
- if(Value != Bit_RESET) *Count += 1;
- else *Count = 0;
- if(*Count > 5)
- {
- *Count = 0; *State = 0;
- printf("\r\n%s Release", Name);
- }
- }
- }
- void BUTTON_Scan(void)
- {
- static uint8_t State[4] = {0, 0, 0, 0};
- static uint8_t Count[4] = {0, 0, 0, 0};
- BUTTON_SubScan(&State[0], &Count[0], GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0), "SW2");
- BUTTON_SubScan(&State[1], &Count[1], GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2), "SW3");
- BUTTON_SubScan(&State[2], &Count[2], GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3), "SW4");
- BUTTON_SubScan(&State[3], &Count[3], GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_2), "SW5");
- }
- void SWITCH_SubScan(uint8_t *State, uint8_t *Count, uint8_t Value, char *Name)
- {
- if(*State == 0)
- {
- if(Value != Bit_RESET) *Count += 1;
- else *Count = 0;
- if(*Count > 5)
- {
- *Count = 0; *State = 1;
- printf("\r\n%s -> OFF", Name);
- }
- }
- else
- {
- if(Value == Bit_RESET) *Count += 1;
- else *Count = 0;
- if(*Count > 5)
- {
- *Count = 0; *State = 0;
- printf("\r\n%s -> ON ", Name);
- }
- }
- }
- void SWITCH_Scan(void)
- {
- static uint8_t State[4] = {0, 0, 0, 0};
- static uint8_t Count[4] = {0, 0, 0, 0};
- SWITCH_SubScan(&State[0], &Count[0], GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_15), "SW1-1");
- SWITCH_SubScan(&State[1], &Count[1], GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_15), "SW1-2");
- SWITCH_SubScan(&State[2], &Count[2], GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_14), "SW1-3");
- SWITCH_SubScan(&State[3], &Count[3], GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13), "SW1-4");
- }
- void ADC_Handler(void)
- {
- uint16_t Result = 0;
- float Voltage = 0.0;
- Result = ADC_Convert(ADC_Channel_10);
- Voltage = (float)Result / 4096 * 3.3;
- printf("\r\n");
- printf("\r\nPB3 <-> ADC1_CH10 : %0.3fV", Voltage);
- Result = ADC_Convert(ADC_Channel_12);
- Voltage = (float)Result / 4096 * 3.3;
- printf("\r\nPB7 <-> ADC1_CH12 : %0.3fV", Voltage);
- printf("\r\n");
- }
- void FLEX_CAN_IRQHandler(void)
- {
- flexcan_frame_t flexcan_frame_rx;
- if(0U != FLEXCAN_GetMbStatusFlags(FLEX_CAN1, 1 << RX_MESSAGE_BUFFER_NUM))
- {
- FLEXCAN_ClearMbStatusFlags(FLEX_CAN1, 1 << RX_MESSAGE_BUFFER_NUM);
- FLEXCAN_ReadRxMb(FLEX_CAN1, RX_MESSAGE_BUFFER_NUM, &flexcan_frame_rx);
- printf("\r\nReceived message from MB%d", RX_MESSAGE_BUFFER_NUM);
- printf("\r\n");
- printf("\r\nrx form = 0x%x", (flexcan_frame_rx.id & CAN_ID_STD_MASK) >> CAN_ID_STD_SHIFT);
- printf("\r\nrx word0 = 0x%x", flexcan_frame_rx.dataWord0);
- printf("\r\nrx word1 = 0x%x", flexcan_frame_rx.dataWord1);
- printf("\r\n");
- }
- __DSB();
- }
- void CAN_Handler(void)
- {
- flexcan_frame_t flexcan_frame_tx;
- flexcan_frame_tx.length = 0x08;
- flexcan_frame_tx.type = (uint8_t)Enum_Flexcan_FrameTypeData;
- flexcan_frame_tx.format = (uint8_t)Enum_Flexcan_FrameFormatStandard;
- flexcan_frame_tx.id = FLEXCAN_ID_STD(0x123);
- flexcan_frame_tx.dataWord0 = CAN_WORD0_DATA_BYTE_0(0x11) |
- CAN_WORD0_DATA_BYTE_1(0x22) |
- CAN_WORD0_DATA_BYTE_2(0x33) |
- CAN_WORD0_DATA_BYTE_3(0x44);
- flexcan_frame_tx.dataWord1 = CAN_WORD1_DATA_BYTE_4(0x55) |
- CAN_WORD1_DATA_BYTE_5(0x66) |
- CAN_WORD1_DATA_BYTE_6(0x77) |
- CAN_WORD1_DATA_BYTE_7(0x88);
- FLEXCAN_TransferSendBlocking(FLEX_CAN1, TX_MESSAGE_BUFFER_NUM, &flexcan_frame_tx);
- }
- void UART2_IRQHandler(void)
- {
- if(UART_GetITStatus(UART2, UART_IT_RXIEN) != RESET)
- {
- printf("%d ", UART_ReceiveData(UART2));
- UART_ClearITPendingBit(UART2, UART_IT_RXIEN);
- }
- }
- void IrDA_SendData(uint8_t Data)
- {
- UART_SendData(UART2, Data);
- while(UART_GetFlagStatus(UART2, UART_IT_TXIEN) == RESET);
- }
- void IrDA_Test(void)
- {
- printf("\r\nIrDA TX : ");
- for(uint8_t i = 0; i < 10; i++)
- {
- IrDA_SendData(i);
- printf("%d ", i);
- }
- printf("\r\n");
- }
- void EEPROM_Test(void)
- {
- uint8_t rBuffer[100], wBuffer[100];
- uint8_t Address = 0, Length = 100;
- printf("\r\n");
- for(uint8_t i = 0; i < Length; i++)
- {
- rBuffer[i] = 0;
- wBuffer[i] = i + 100;
- }
- printf("\r\nEEPROM Write......");
- EEPROM_WriteData(Address, wBuffer, Length);
- printf("\r\n");
- printf("\r\nEEPROM Read :");
- EEPROM_ReadData(Address, rBuffer, Length);
- for(uint8_t i = 0; i < Length; i++)
- {
- if((i % 16) == 0) printf("\r\n");
- printf("0x%02x ", rBuffer[i]);
- }
- printf("\r\n");
- }
- void W25Q16_Test(void)
- {
- uint8_t Buffer[128];
- W25Q16_ReadDeviceID();
- W25Q16_ReadJEDEC_ID();
- for(uint16_t i = 0; i < 512; i++)
- {
- printf("\r\nW25Q16 Erase Sector[%03d]......", i);
- W25Q16_SectorErase(i);
- }
- printf("\r\n");
- printf("\r\nW25Q16 Erase Sector[0]......");
- W25Q16_SectorErase(0);
- printf("\r\nW25Q16 Read :");
- W25Q16_FastRead(0, Buffer, sizeof(Buffer));
- for(uint8_t i = 0; i < sizeof(Buffer); i++)
- {
- if((i % 16) == 0) printf("\r\n");
- printf("0x%02x ", Buffer[i]);
- }
- printf("\r\n");
- printf("\r\nW25Q16 Write......");
- memset(Buffer, 0, sizeof(Buffer));
- for(uint8_t i = 0; i < sizeof(Buffer); i++)
- {
- Buffer[i] = i;
- }
- W25Q16_PageProgram(0, Buffer, sizeof(Buffer));
- printf("\r\nW25Q16 Read :");
- W25Q16_FastRead(0, Buffer, sizeof(Buffer));
- for(uint8_t i = 0; i < sizeof(Buffer); i++)
- {
- if((i % 16) == 0) printf("\r\n");
- printf("0x%02x ", Buffer[i]);
- }
- printf("\r\n");
- }
- void LCD_ShowLOG(uint8_t StartX, uint8_t StartY, const char *str)
- {
- while(*str != '\0')
- {
- if(*str < 0x7F)
- {
- if(StartX > (128 - 8))
- {
- StartX = 0; StartY += 16;
- }
- if(StartY > (128 - 16))
- {
- StartX = 0; StartY = 0;
- LCD_ClearScreen(BACKCOLOR);
- }
- LCD_ShowEN(StartX, StartY, *str);
- StartX += 0x08;
- str += 0x01;
- }
- else
- {
- if(StartX > (128 - 16))
- {
- StartX = 0; StartY += 16;
- }
- if(StartY > (128 - 16))
- {
- StartX = 0; StartY = 0;
- LCD_ClearScreen(BACKCOLOR);
- }
- LCD_ShowCN(StartX, StartY, str);
- StartX += 0x10;
- str += 0x02;
- }
- }
- }
- void LCD_DrawImage(void)
- {
- uint16_t Color = 0;
- uint32_t Index = 0;
- for(uint32_t i = 0; i < 47; i++)
- {
- for(uint32_t j = 0; j < 128; j++)
- {
- Color = gImage_**[Index++];
- Color <<= 8;
- Color |= gImage_**[Index++];
- LCD_DrawPoint(j, i, Color);
- }
- }
- }
- void WAV_PlaySong(void)
- {
- WAV_TypeDef WaveFile;
- if(WAV_PlayState == 0)
- {
- if(WAV_DecodeFile(&WaveFile, 0x00000000) == 0)
- {
- if((WaveFile.BitsPerSample == 16) && (WaveFile.nChannels == 2) &&
- (WaveFile.SampleRate > 44000) && (WaveFile.SampleRate < 48100))
- {
- WAV_NextIndex = 0;
- WAV_PlayEnded = 0;
- WAV_TxLength = 0;
- WAV_PlayState = 1;
- printf("\r\n");
- printf("\r\nWAV Data Size : %d, Data Start : 0x%08x", WAV_DataSize, WAV_Offset);
- printf("\r\n");
- WAV_PrepareData();
- WAV_PlayHandler();
- }
- else
- {
- printf("\r\nWAV File Format Error!\r\n"); return;
- }
- }
- else
- {
- printf("\r\nNo WAV File!\r\n"); return;
- }
- }
- else
- {
- printf("\r\nThe Song Is Not Over Yet!\r\n");
- }
- }
- 本文系21ic原创,未经许可禁止转载!
网友评论
- 联系人:巧克力娃娃
- 邮箱:board@21ic.com
- 我要投稿
-
欢迎入驻,开放投稿
-
人均百万?英伟达中国员工收入曝光! 2024-08-29
-
《黑神话:悟空》玩家硬盘升级攻略:提升游戏体验,畅享3A大作 2024-08-29
-
数睿数据参加《系统与软件工程 低代码开发平台通用技术要求》国家标准编制 2024-08-29
- NRF52810蓝牙数字耳机找人定制
预算:¥30005天前
- 125KW模块式PCS软硬件外包开发
预算:¥1100000015小时前
- 12V汽车启动电源项目BMS设计
预算:¥50000023小时前
- 数据可视化软件 开发
预算:¥5000023小时前
- PLC项目调试修改
预算:¥100001天前
- 起动电机控制器开发
预算:¥1100001天前