[活动专区] 【N32G430开发板试用】可视呼叫门铃演示样机

[复制链接]
2235|11
 楼主| xld0932 发表于 2022-7-25 19:57 | 显示全部楼层 |阅读模式
本帖最后由 xld0932 于 2023-7-19 13:24 编辑

@安小芯    @21小跑堂


概述
基于N32G430C8L7-STB开发板搭配外围功能模块实现可视呼叫门铃的功能演示。通过板载的按键检测实现门铃呼叫、开锁功能;当按键呼叫按键后,通过摄像头将门口景象以静态图片的形式显示在TFT显示屏上,同时播放门铃音乐;当按键开锁按键后,在TFT显示屏上显示开锁提示。功能描述虽然简单,但使用的MCU外设技术点不少哦,涉及到了GPIO、SPI、I2S、DMA、UART、FLASH、RTC等,主要是想通过实现这个演示样机的功能来熟悉国民MCU产品,最后为了完成上述功能还需要在标准板的基础上再画一块实现上述功能的扩展板。


软件功能
  • 通过板载的按键实现模拟门铃呼叫按键、开锁的功能;
  • 通过USART2与RS485模块连接,RS485模块连接到远端的门口摄像头,通过发送指令的形式抓拍图片,再通过指令回传图片数据;
  • 通过SPI接口连接SPI接口的TFT显示屏,显示相关信息(**、开锁提示、摄像头图片、音频文件等);
  • 通过SPI接口连接SPI FLASH存储模块,在存储模块中存放GBK中文字库、**图片数据等信息;通过PC端的SecureCRT软件与N32G430C8L7-STB板载的USART1进行通讯,将资源文件通过Xmodem协议下载到SPI FLASH存储模块中;
  • 通过I2S接口连接CS4344音频模块,通过音频线将CS4344模块与音箱相连接;


系统框图
由于N32G430C8L7芯片资源只带有64KB的FLASH和16KB的SRAM空间,所以需要扩展SPI FLASH来存放一些资源文件;在系统中使用I2S来播放WAV文件,为了达到播放音频流畅的效果,WAV文件的读取使用了双缓存结合DMA的实现方式,所以占用了部分的SRAM空间;对于RS485摄像头回传的图片数据是JPEG格式的,所以在实现方案中我们使用了TJPGD3软件解码库,将JPEG格式的图片数据进行解析,并显示到TFT显示屏上,对于软件解码JPEG图片需要占用不少的SRAM的空间,这样留给摄像头图片读回存放的空间就已经不够用了,所以为了解决这个问题,我们想到将摄像头读回的JPEG图片数据暂存在MCU内部FLASH空间,这样就解决了SRAM空间不足的问题了!
系统框图.jpg


硬件准备
  • N32G430C8L7-STB开发板
  • N32G430C8L7-STB_EBK功能扩展板(RS485模块、CS4344模块、SPI FLASH模块、TFT显示屏)
  • RS485接口摄像头
  • 音箱
  • 相关数据连接线
硬件环境.jpg


N32G430C8L7-STB_EBK功能扩展板
原理图
扩展板原理图.png

PCB-2D正面图
扩展板PCB.png

焊接成品
扩展板成品图.jpg


资源文件
GBK中文字库存放在SPI FLASH起始地址为0的位置、音频文件存放在SPI FLASH起始地址为0x100000的位置、**等图片信息存放在SPI FLASH起始地址为0x200000的位置;在下载资源到SPI FLASH时,需要将config.h文件中宏定义修改为如下所示:
下载配置.png

然后打开PC端的SecureCRT软件下载资源文件,输入的命令为XMODEM 1 XXXXX,其中1表示PC端将数据下传到MCU,经MCU将数据写入到SPI FLASH,第二个参数是指令下载的起始地址;XMODEM协议在传输时带有校验和重传机制,所以在出现ERROR后不用担心数据丢失或者数据不正确,如下图所示:
下载资源.png

在TFT初始显示界面上有两个**显示,如果这些图片存放在MCU FLASH空间会导致后面的功能代码空间不足,所以就存放在SPI FLASH存储了;在取模时需要结合代码的实现来设定,如下所示:
取模1.jpg 取模2.jpg

其中勾选了包含图像头数据为了获取图片的宽度、高度信息,方便程序中排版显示。


代码实现
代码部分仅摘录了部分,完整的功能代码可以下载文末的软件工程源代码附件。

摄像头相关部分
  1. void CAMERA_RxHandler(void)
  2. {
  3.     static uint8_t  RxStart   = 0;
  4.     static uint16_t RxIndex   = 0;
  5.     static uint8_t  RxBuffer[600];
  6.     static uint32_t RxLength  = 0;

  7.     if(QUEUE_EMPTY(QUEUE_CAMERA_IDX) == 0)
  8.     {
  9.         uint8_t RxData = QUEUE_READ(QUEUE_CAMERA_IDX);

  10.         if(RxStart == 0)
  11.         {
  12.             if(RxData == CAMERA_START)
  13.             {
  14.                 RxStart = 1;
  15.                 RxIndex = 0;

  16.                 memset(RxBuffer, 0, sizeof(RxBuffer));

  17.                 RxBuffer[RxIndex++] = RxData;
  18.             }
  19.         }
  20.         else
  21.         {
  22.             if(RxIndex == 1)
  23.             {
  24.                 RxBuffer[RxIndex++] = RxData;
  25.             }
  26.             else
  27.             {
  28.                 RxBuffer[RxIndex++] = RxData;

  29.                 switch(RxBuffer[1])
  30.                 {
  31.                     case CAMERA_CMD_H:
  32.                         if((RxIndex ==  4) && (RxBuffer[RxIndex-1] == CAMERA_END))
  33.                         {
  34.                             RxStart = 0;
  35.                         }
  36.                         break;

  37.                     case CAMERA_CMD_R:
  38.                         if((RxIndex == 10) && (RxBuffer[RxIndex-1] == CAMERA_END))
  39.                         {
  40.                             RxStart = 0;

  41.                             CAMERA_PictureSize   = RxBuffer[6];
  42.                             CAMERA_PictureSize <<= 8;
  43.                             CAMERA_PictureSize  |= RxBuffer[5];
  44.                             CAMERA_PictureSize <<= 8;
  45.                             CAMERA_PictureSize  |= RxBuffer[4];
  46.                             CAMERA_PictureSize <<= 8;
  47.                             CAMERA_PictureSize  |= RxBuffer[3];

  48.                             CAMERA_PacketTotal   = RxBuffer[8];
  49.                             CAMERA_PacketTotal <<= 8;
  50.                             CAMERA_PacketTotal  |= RxBuffer[7];

  51.                             CAMERA_CMD_Running = 0;
  52.                         }
  53.                         break;

  54.                     case CAMERA_CMD_E:
  55.                         if((RxIndex ==  4) && (RxBuffer[RxIndex-1] == CAMERA_END))
  56.                         {
  57.                             RxStart = 0;
  58.                         }
  59.                         break;

  60.                     case CAMERA_CMD_F:
  61.                         if(CAMERA_PacketIndex < CAMERA_PacketTotal)
  62.                         {
  63.                             RxLength = CAMERA_PACKET_SIZE;
  64.                         }
  65.                         else
  66.                         {
  67.                             RxLength = CAMERA_PictureSize % CAMERA_PACKET_SIZE;
  68.                         }

  69.                         if(RxIndex == (RxLength + 9))
  70.                         {
  71.                             RxStart = 0;

  72.                             uint16_t PacketIndex = 0;
  73.                             uint16_t PictureSize = 0;
  74.                             uint32_t SRAM_Offset = 0;

  75.                             PacketIndex   = RxBuffer[4];
  76.                             PacketIndex <<= 8;
  77.                             PacketIndex  |= RxBuffer[3];

  78.                             PictureSize   = RxBuffer[6];
  79.                             PictureSize <<= 8;
  80.                             PictureSize  |= RxBuffer[5];

  81.                             SRAM_Offset = (PacketIndex - 1) * CAMERA_PACKET_SIZE;

  82.                             if(((PacketIndex - 1) % 4) == 0)
  83.                             {
  84.                                 FLASH_Unlock();
  85.                                 FLASH_One_Page_Erase(0x0800A000 + SRAM_Offset);
  86.                                 FLASH_Lock();
  87.                             }

  88.                             FLASH_Unlock();

  89.                             for(uint16_t i = 0; i < PictureSize; i+=4)
  90.                             {
  91.                                 FLASH_Word_Program(i+SRAM_Offset+0x0800A000, *((uint32_t *)(&RxBuffer[i+7])));
  92.                             }

  93.                             FLASH_Lock();

  94.                             CAMERA_CMD_Running = 0;
  95.                         }
  96.                         break;

  97.                     case CAMERA_CMD_D: break;
  98.                     case CAMERA_CMD_I: break;
  99.                     case CAMERA_CMD_Q: break;
  100.                     default:
  101.                         break;
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }


TFT相关部分
  1. void LCD_ShowEN(uint16_t X, uint16_t Y, char ch)
  2. {  
  3.     uint8_t  Data  = 0;
  4.     uint16_t Color = 0;

  5.     for(uint8_t i = 0; i < 16; i++)
  6.     {
  7.         Data = ASCII_1608[ch - 32][i];

  8.         for(uint8_t j = 0; j < 8; j++)
  9.         {
  10.             if((Data >> j) & 0x01) Color = LCD_Forecolor;
  11.             else                   Color = BACKCOLOR;

  12.             LCD_DrawPoint(X+j, Y+i, Color);
  13.         }
  14.     }
  15. }

  16. void LCD_ShowCN(uint16_t StartX, uint16_t StartY, const char *str)
  17. {
  18.     uint8_t Buffer[32];
  19.     uint8_t Array[16][16];
  20.     uint8_t Point[16][16];

  21.     memset(Buffer, 0xFF, sizeof(Buffer));

  22.     SPI_FLASH_GetGBK(str, Buffer);

  23.     for(uint8_t i = 0; i < 8; i++)
  24.     {
  25.         for(uint8_t j = 0; j < 4; j++)
  26.         {
  27.             uint8_t Data = Buffer[i*4+j];

  28.             for(uint8_t k = 0; k < 4; k++)
  29.             {
  30.                 if(Data & (0x08 >> (k-0)))  Array[i*2+0][j*4+k-0] = 1;
  31.                 else                        Array[i*2+0][j*4+k-0] = 0;
  32.             }

  33.             for(uint8_t k = 4; k < 8; k++)
  34.             {
  35.                 if(Data & (0x80 >> (k-4)))  Array[i*2+1][j*4+k-4] = 1;
  36.                 else                        Array[i*2+1][j*4+k-4] = 0;
  37.             }
  38.         }
  39.     }

  40.     for(uint8_t i = 0; i < 16; i++)
  41.     {
  42.         for(uint8_t j = 0; j < 16; j++)
  43.         {
  44.             Point[i][j] = Array[j][15-i];
  45.         }
  46.     }

  47.     for(uint8_t i = 0; i < 16; i++)
  48.     {
  49.         for(uint8_t j = 0; j < 16; j++)
  50.         {
  51.             if(Point[15-i][j])
  52.             {
  53.                 LCD_DrawPoint(StartX+i, StartY+j, LCD_Forecolor);
  54.             }
  55.             else
  56.             {
  57.                 LCD_DrawPoint(StartX+i, StartY+j, BACKCOLOR);
  58.             }
  59.         }
  60.     }
  61. }

  62. void LCD_ShowLOG(uint16_t StartX, uint16_t StartY, const char *str)
  63. {
  64.     while(*str != '\0')
  65.     {
  66.         if(*str < 0x7F)
  67.         {
  68.             if(StartX > (LCD_WIDTH  - 8))
  69.             {
  70.                 StartX = 0; StartY += 16;
  71.             }

  72.             if(StartY > (LCD_HEIGHT - 16))
  73.             {
  74.                 StartX = 0; StartY = 0;

  75.                 LCD_ClearScreen(BACKCOLOR);
  76.             }

  77.             LCD_ShowEN(StartX, StartY, *str);

  78.             StartX += 0x08;
  79.             str    += 0x01;
  80.         }
  81.         else
  82.         {
  83.             if(StartX > (LCD_WIDTH  - 16))
  84.             {
  85.                 StartX = 0; StartY += 16;
  86.             }

  87.             if(StartY > (LCD_HEIGHT - 16))
  88.             {
  89.                 StartX = 0; StartY = 0;

  90.                 LCD_ClearScreen(BACKCOLOR);
  91.             }

  92.             LCD_ShowCN(StartX, StartY,  str);

  93.             StartX += 0x10;
  94.             str    += 0x02;
  95.         }
  96.     }
  97. }

  98. void LCD_DrawImage(void)
  99. {
  100.     uint16_t StartX = 0, StartY = 0;
  101.     uint16_t Width  = 0, Height = 0, Index = 0;
  102.     uint32_t Address = 0, Offset = 0, Length = 0;

  103.     uint8_t  Buffer[200];


  104.     Address = 0x20204C;
  105.     Offset  = 0;
  106.     Length  = 0x001A84;
  107.     Index   = 8;

  108.     SPI_FLASH_FastRead(Address + Offset, Buffer, 8);

  109.     Width    = Buffer[2];
  110.     Width  <<= 8;
  111.     Width   |= Buffer[3];

  112.     Height   = Buffer[4];
  113.     Height <<= 8;
  114.     Height  |= Buffer[5];

  115.     StartX = (240 - Width ) / 2;
  116.     StartY = 30;

  117.     LCD_SetAddress(StartX, StartY, StartX + Width - 1, StartY + Height - 1);

  118.     GPIO_Pins_Set(GPIOB, GPIO_PIN_11);

  119.     do
  120.     {
  121.         SPI_FLASH_FastRead(Address + Offset + Index, Buffer, sizeof(Buffer));

  122.         for(uint8_t i = 0; i < sizeof(Buffer); i++)
  123.         {
  124.             if(Index++ < Length)
  125.             {
  126.                 LCD_SPI_WriteByte(Buffer[i]);
  127.             }
  128.         }
  129.     }while(Index < Length);


  130.     Address = 0x200000;
  131.     Offset  = 0;
  132.     Length  = 0x00204C;
  133.     Index   = 8;

  134.     SPI_FLASH_FastRead(Address + Offset, Buffer, 8);

  135.     Width    = Buffer[2];
  136.     Width  <<= 8;
  137.     Width   |= Buffer[3];

  138.     Height   = Buffer[4];
  139.     Height <<= 8;
  140.     Height  |= Buffer[5];

  141.     StartX = (240 - Width ) / 2;
  142.     StartY = 255;

  143.     LCD_SetAddress(StartX, StartY, StartX + Width - 1, StartY + Height - 1);

  144.     GPIO_Pins_Set(GPIOB, GPIO_PIN_11);

  145.     do
  146.     {
  147.         SPI_FLASH_FastRead(Address + Offset + Index, Buffer, sizeof(Buffer));

  148.         for(uint8_t i = 0; i < sizeof(Buffer); i++)
  149.         {
  150.             if(Index++ < Length)
  151.             {
  152.                 LCD_SPI_WriteByte(Buffer[i]);
  153.             }
  154.         }
  155.     }while(Index < Length);
  156. }


WAV相关部分
  1. uint8_t WAV_DecodeFile(WAV_TypeDef *pWav, uint32_t Address)
  2. {
  3.     ChunkRIFF_TypeDef *WAV_RIFF;
  4.     ChunkFMT_TypeDef  *WAV_FMT ;
  5.     ChunkFACT_TypeDef *WAV_FACT;
  6.     ChunkDATA_TypeDef *WAV_DATA;

  7.     uint8_t WAV_HeadBuffer[512];

  8.     SPI_FLASH_FastRead(Address, WAV_HeadBuffer, 512);

  9.     /* 获取RIFF块 */
  10.     WAV_RIFF = (ChunkRIFF_TypeDef *)WAV_HeadBuffer;

  11.     /* 是WAV格式文件 */
  12.     if(WAV_RIFF->Format == 0x45564157)
  13.     {
  14.         /* 获取FMT块 */
  15.         WAV_FMT  = (ChunkFMT_TypeDef *)(WAV_HeadBuffer+12);

  16.         /* 读取FACT块 */
  17.         WAV_FACT = (ChunkFACT_TypeDef *)(WAV_HeadBuffer+12+8+WAV_FMT->ChunkSize);

  18.         if((WAV_FACT->ChunkID == 0x74636166) || (WAV_FACT->ChunkID == 0x5453494C))
  19.         {
  20.             /* 具有FACT/LIST块的时候(未测试) */
  21.             pWav->DataStart=12+8+WAV_FMT->ChunkSize+8+WAV_FACT->ChunkSize;
  22.         }
  23.         else
  24.         {
  25.             pWav->DataStart=12+8+WAV_FMT->ChunkSize;
  26.         }

  27.         /* 读取DATA块 */
  28.         WAV_DATA = (ChunkDATA_TypeDef *)(WAV_HeadBuffer+pWav->DataStart);

  29.         /* 解析成功 */
  30.         if(WAV_DATA->ChunkID == 0x61746164)
  31.         {
  32.             pWav->AudioFormat   = WAV_FMT->AudioFormat;     /* 音频格式 */
  33.             pWav->nChannels     = WAV_FMT->NumOfChannels;   /* 通道数 */
  34.             pWav->SampleRate    = WAV_FMT->SampleRate;      /* 采样率 */
  35.             pWav->BitRate       = WAV_FMT->ByteRate*8;      /* 得到位速 */
  36.             pWav->BlockAlign    = WAV_FMT->BlockAlign;      /* 块对齐 */
  37.             pWav->BitsPerSample = WAV_FMT->BitsPerSample;   /* 位数,16/24/32位 */

  38.             pWav->DataSize      = WAV_DATA->ChunkSize;      /* 数据块大小 */
  39.             pWav->DataStart     = pWav->DataStart+8;        /* 数据流开始的地方 */

  40.             printf("\r\npWav->AudioFormat   : %d", pWav->AudioFormat);
  41.             printf("\r\npWav->nChannels     : %d", pWav->nChannels);
  42.             printf("\r\npWav->SampleRate    : %d", pWav->SampleRate);
  43.             printf("\r\npWav->BitRate       : %d", pWav->BitRate);
  44.             printf("\r\npWav->BlockAlign    : %d", pWav->BlockAlign);
  45.             printf("\r\npWav->BitsPerSample : %d", pWav->BitsPerSample);
  46.             printf("\r\npWav->DataSize      : %d", pWav->DataSize);
  47.             printf("\r\npWav->DataStart     : %d", pWav->DataStart);

  48.             WAV_Offset   = pWav->DataStart + Address;
  49.             WAV_DataSize = pWav->DataSize;
  50.         }
  51.     }

  52.     return 0;
  53. }

  54. void WAV_PrepareData(void)
  55. {
  56.     if(WAV_NextIndex == 0)
  57.     {
  58.         SPI_FLASH_FastRead(WAV_Offset + WAV_TxLength, WAV_DataBuffer[0], WAV_BUFFER_SIZE);
  59.     }
  60.     else
  61.     {
  62.         SPI_FLASH_FastRead(WAV_Offset + WAV_TxLength, WAV_DataBuffer[1], WAV_BUFFER_SIZE);
  63.     }

  64.     WAV_TxLength += WAV_BUFFER_SIZE;

  65.     if(WAV_TxLength > WAV_DataSize) WAV_PlayEnded = 1;
  66. }

  67. void WAV_PlayHandler(void)
  68. {
  69.     if(WAV_PlayEnded == 0)
  70.     {
  71.         CS4344_I2S_DMA_Transfer((uint16_t *)&WAV_DataBuffer[WAV_NextIndex][0], (WAV_BUFFER_SIZE / 2));
  72.     }
  73.     else
  74.     {
  75.         DMA_Channel_Disable(DMA_CH1);

  76.         printf("\r\nWAV Play Finish!\r\n");     WAV_PlayState = 0;
  77.     }

  78.     if(WAV_NextIndex == 0) WAV_NextIndex = 1;
  79.     else                   WAV_NextIndex = 0;
  80. }

  81. void WAV_PlaySong(void)
  82. {
  83.     WAV_TypeDef WaveFile;

  84.     if(WAV_PlayState == 0)
  85.     {
  86.         if(WAV_DecodeFile(&WaveFile, 0x100000) == 0)
  87.         {
  88.             if((WaveFile.BitsPerSample == 16) && (WaveFile.nChannels == 2) &&
  89.                (WaveFile.SampleRate  > 44000) && (WaveFile.SampleRate < 48100))
  90.             {
  91.                 WAV_NextIndex = 0;
  92.                 WAV_PlayEnded = 0;
  93.                 WAV_TxLength  = 0;
  94.                 WAV_PlayState = 1;

  95.                 printf("\r\n");
  96.                 printf("\r\nWAV Data Size : %d, Data Start : 0x%08x", WAV_DataSize, WAV_Offset);
  97.                 printf("\r\n");

  98.                 WAV_PrepareData();
  99.                 WAV_PlayHandler();
  100.             }
  101.             else
  102.             {
  103.                 printf("\r\nWAV File Format Error!\r\n"); return;
  104.             }
  105.         }
  106.         else
  107.         {
  108.             printf("\r\nNo WAV File!\r\n"); return;
  109.         }
  110.     }
  111.     else
  112.     {
  113.         printf("\r\nThe Song Is Not Over Yet!\r\n");
  114.     }
  115. }


KEY相关部分
  1. void KEY_Init(void)
  2. {
  3.     GPIO_InitType GPIO_InitStructure;

  4.     RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOA);

  5.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  6.     GPIO_InitStructure.Pin       = GPIO_PIN_0;
  7.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
  8.     GPIO_InitStructure.GPIO_Pull = GPIO_NO_PULL;
  9.     GPIO_Peripheral_Initialize(GPIOA, &GPIO_InitStructure);

  10.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  11.     GPIO_InitStructure.Pin       = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6;
  12.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
  13.     GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP;
  14.     GPIO_Peripheral_Initialize(GPIOA, &GPIO_InitStructure);

  15.     TASK_Append(TASK_ID_KEY, KEY_Scan, 10);
  16. }

  17. void KEY_Handler(char *Name, uint8_t State, uint8_t Value)
  18. {
  19.     if(strcmp(Name, "WAKEUP") == 0)
  20.     {
  21.         if(State == 0)
  22.         {
  23.             CAMERA_TakePhoto();

  24.             for(uint16_t i = 1; i <= CAMERA_PacketTotal; i++)
  25.             {
  26.                 CAMERA_GetPacket(i);
  27.             }

  28.             CAMERA_DrawImage();

  29. #if ENABLE_WAV
  30.             WAV_PlaySong();
  31. #endif
  32.         }
  33.     }

  34.     if(strcmp(Name, "KEY3") == 0)
  35.     {
  36.         if(State == 1)
  37.         {
  38.             LCD_SetForecolor(FORECOLOR);
  39.             LCD_ShowLOG(76, 230, "正在开门...");
  40.         }
  41.         else
  42.         {
  43.             LCD_SetForecolor(FORECOLOR);
  44.             LCD_ShowLOG(76, 230, "           ");
  45.         }
  46.     }
  47. }

  48. void KEY_SubScan(uint8_t *State, uint8_t *Count, uint8_t Value, uint8_t Active, char *Name)
  49. {
  50.     if(*State == 0)
  51.     {
  52.         if(Value == Active) *Count += 1;
  53.         else                *Count  = 0;

  54.         if(*Count > 5)
  55.         {
  56.             *Count = 0; *State = 1;
  57.             printf("\r\n%s Pressed", Name); KEY_Handler(Name, 1, false);
  58.         }
  59.     }
  60.     else
  61.     {
  62.         if(Value != Active) *Count += 1;
  63.         else                *Count  = 0;

  64.         if(*Count > 5)
  65.         {
  66.             *Count = 0; *State = 0;
  67.             printf("\r\n%s Release", Name); KEY_Handler(Name, 0, true);
  68.         }
  69.     }
  70. }

  71. void KEY_Scan(void)
  72. {
  73.     static uint8_t KeyState[4] = {0, 0, 0, 0};
  74.     static uint8_t KeyCount[4] = {0, 0, 0, 0};

  75.     KEY_SubScan(&KeyState[0], &KeyCount[0], GPIO_Input_Pin_Data_Get(GPIOA, GPIO_PIN_0), PIN_SET,   "WAKEUP");
  76.     KEY_SubScan(&KeyState[1], &KeyCount[1], GPIO_Input_Pin_Data_Get(GPIOA, GPIO_PIN_4), PIN_RESET, "KEY1");
  77.     KEY_SubScan(&KeyState[2], &KeyCount[2], GPIO_Input_Pin_Data_Get(GPIOA, GPIO_PIN_5), PIN_RESET, "KEY2");
  78.     KEY_SubScan(&KeyState[3], &KeyCount[3], GPIO_Input_Pin_Data_Get(GPIOA, GPIO_PIN_6), PIN_RESET, "KEY3");
  79. }


运行效果 & 演示视频
https://www.bilibili.com/video/BV1XG4y1i7wr?vd_source=c2d3413b74687345dfc8205a8d735598
待机显示界面.jpg


附件
软件工程源代码: VideoDoorPhone_20220724.zip (473.49 KB, 下载次数: 53)
功能扩展板原理图: Schematic_N32G430C8L7-STB_EBK_CAMERA_2022-07-25.pdf (92.98 KB, 下载次数: 19)


其它
在调试SPI接口时,MCU资源只配备了2路SPI,其中一路我们需要当I2S使用,那剩下的那一路就需要驱动SPI FLASH和SPI接口的TFT显示屏,这样就需要不同的CS引脚来控制;我们将CS引脚配置为硬件控制和软件控制方式的时候,代码实现是不同的,在软件控制时需要特别注意,具体参考如下代码:
  1. void LCD_InitSPI2(void)
  2. {
  3.     GPIO_InitType GPIO_InitStructure;
  4.     SPI_InitType  SPI_InitStructure;

  5.     RCC_APB2_Peripheral_Clock_Enable(RCC_APB2_PERIPH_SPI2);
  6.     RCC_AHB_Peripheral_Clock_Enable( RCC_AHB_PERIPH_GPIOB);

  7. #if 1
  8.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  9.     GPIO_InitStructure.Pin       = GPIO_PIN_12;
  10.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
  11.     GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);

  12.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  13.     GPIO_InitStructure.Pin            = GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  14.     GPIO_InitStructure.GPIO_Mode      = GPIO_MODE_AF_PP;
  15.     GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI2;
  16.     GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
  17. #else
  18.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  19.     GPIO_InitStructure.Pin            = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  20.     GPIO_InitStructure.GPIO_Mode      = GPIO_MODE_AF_PP;
  21.     GPIO_InitStructure.GPIO_Alternate = GPIO_AF1_SPI2;
  22.     GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
  23. #endif

  24.     SPI_I2S_Reset(SPI2);

  25.     SPI_Initializes_Structure(&SPI_InitStructure);
  26.     SPI_InitStructure.DataDirection  = SPI_DIR_DOUBLELINE_FULLDUPLEX;
  27.     SPI_InitStructure.SpiMode        = SPI_MODE_MASTER;
  28.     SPI_InitStructure.DataLen        = SPI_DATA_SIZE_8BITS;
  29.     SPI_InitStructure.CLKPOL         = SPI_CLKPOL_LOW;
  30.     SPI_InitStructure.CLKPHA         = SPI_CLKPHA_FIRST_EDGE;
  31.     SPI_InitStructure.NSS            = SPI_NSS_SOFT;
  32.     SPI_InitStructure.BaudRatePres   = SPI_BR_PRESCALER_8;
  33.     SPI_InitStructure.FirstBit       = SPI_FB_MSB;
  34.     SPI_InitStructure.CRCPoly        = 7;
  35.     SPI_Initializes(SPI2, &SPI_InitStructure);

  36. #if 1
  37.     SPI_NSS_Config(SPI2, SPI_NSS_SOFT);
  38.     SPI_Set_Nss_Level(SPI2, SPI_NSS_HIGH);
  39. #else
  40.     SPI_NSS_Config(SPI2, SPI_NSS_HARD);
  41.     SPI_SS_Output_Enable(SPI2);
  42. #endif

  43.     SPI_ON(SPI2);
  44. }

另外就是在实现I2S功能时,也特别感谢国民技术和王工的支持!!!

maqianqu 发表于 2022-8-16 22:14 | 显示全部楼层
这个没有功能代码吗   
 楼主| xld0932 发表于 2022-8-17 08:54 | 显示全部楼层
maqianqu 发表于 2022-8-16 22:14
这个没有功能代码吗

不是有上传附件嘛……完整的软件工程代码呀,怎么说没有呢?
 楼主| xld0932 发表于 2022-8-24 15:12 | 显示全部楼层
uptown 发表于 2022-9-3 17:23 | 显示全部楼层
可以实现图片的传输吗
adolphcocker 发表于 2022-9-3 20:33 | 显示全部楼层
这个看着比较高端了。   
timfordlare 发表于 2022-9-3 20:52 | 显示全部楼层
语音的传输使用压缩算法了吗   
 楼主| xld0932 发表于 2022-9-4 20:14 | 显示全部楼层
timfordlare 发表于 2022-9-3 20:52
语音的传输使用压缩算法了吗

语音是通过I2S接口实现的,音频文件(WAV文件)存放在SPI FLASH中,通过MCU的SPI接口读取SPI FLASH中的音频数据进行软件解码,然后通过I2S接口传输音频数据,进行播放的……
janewood 发表于 2022-12-5 21:16 | 显示全部楼层
这个图像是怎么传输呢?              
claretttt 发表于 2022-12-5 21:56 | 显示全部楼层
楼主做的这个可视化门铃确实很棒。
alvpeg 发表于 2022-12-6 12:50 | 显示全部楼层
使用的是什么音频模块?              
wwppd 发表于 2022-12-6 15:41 | 显示全部楼层
能不能实现远程wifi通信呢              
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:King.Xu

77

主题

3023

帖子

38

粉丝
快速回复 在线客服 返回列表 返回顶部