在线时间97 小时
UID3332856
注册时间2016-11-28
NXP金币316
该用户从未签到
金牌会员
- 积分
- 1081
- 最后登录
- 2024-7-3
|
1 . 本项目拟采用心电传感器MAX30003WING开发板,使用SPI端口连接。这个开发板是配套美信WING开发板,因此引脚都是兼容的,对应采用K32L2B3则连接方法如下,采用了SPI连接线和中断使能,
在开发板的连接如下,
因此需要按照对应的引脚连接到MCU上实现功能。
具体的外部连接只需要连接2点电极,含接触电势的等效电路图为,
2. 程序的逻辑
2.1 设定串口传输为115200-8-1-N
2.2 设定ecg FIFO almost full interrupt 的中断引脚
2.3 设定SPI的通道,MOSI,MISO,SCK的引脚
2.4 配置ECG的参数设定,这些在CMD的指令中传输。
2.5 通过对应SPI的接口参数选择,读取数据,直接显示出采集的ECG数据
2.6 通过串口数据显示出来。
3 使用SPI的范例Demo,运行通过,可以作为开发的模板继续进行。
- /*
- * Copyright (c) 2015, Freescale Semiconductor, Inc.
- * Copyright 2016-2017 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
- #include "fsl_spi.h"
- #include "board.h"
- #include "fsl_debug_console.h"
- #include "pin_mux.h"
- #include "clock_config.h"
- /*******************************************************************************
- * Definitions
- ******************************************************************************/
- #define EXAMPLE_SPI_MASTER SPI0
- #define EXAMPLE_SPI_MASTER_SOURCE_CLOCK kCLOCK_BusClk
- #define EXAMPLE_SPI_MASTER_CLK_FREQ CLOCK_GetFreq(kCLOCK_BusClk)
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- /*******************************************************************************
- * Variables
- ******************************************************************************/
- #define BUFFER_SIZE (64)
- static uint8_t srcBuff[BUFFER_SIZE];
- static uint8_t destBuff[BUFFER_SIZE];
- spi_master_handle_t handle;
- static volatile bool masterFinished = false;
- /*******************************************************************************
- * Code
- ******************************************************************************/
- static void masterCallback(SPI_Type *base, spi_master_handle_t *masterHandle, status_t status, void *userData)
- {
- masterFinished = true;
- }
- int main(void)
- {
- spi_transfer_t xfer = {0};
- spi_master_config_t userConfig;
- uint32_t err = 0;
- uint32_t i = 0;
- uint32_t srcFreq = 0;
- BOARD_InitPins();
- BOARD_BootClockRUN();
- BOARD_InitDebugConsole();
- PRINTF("\n\rMaster Start...\n\r");
- /*
- * userConfig.enableStopInWaitMode = false;
- * userConfig.polarity = kSPI_ClockPolarityActiveHigh;
- * userConfig.phase = kSPI_ClockPhaseFirstEdge;
- * userConfig.direction = kSPI_MsbFirst;
- * userConfig.dataMode = kSPI_8BitMode;
- * userConfig.txWatermark = kSPI_TxFifoOneHalfEmpty;
- * userConfig.rxWatermark = kSPI_RxFifoOneHalfFull;
- * userConfig.pinMode = kSPI_PinModeNormal;
- * userConfig.outputMode = kSPI_SlaveSelectAutomaticOutput;
- * userConfig.baudRate_Bps = 500000U;
- */
- SPI_MasterGetDefaultConfig(&userConfig);
- srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ;
- SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq);
- /* Init Buffer */
- for (i = 0; i < BUFFER_SIZE; i++)
- {
- srcBuff[i] = i;
- }
- /* Send to slave */
- xfer.txData = srcBuff;
- xfer.rxData = destBuff;
- xfer.dataSize = BUFFER_SIZE;
- SPI_MasterTransferCreateHandle(EXAMPLE_SPI_MASTER, &handle, masterCallback, NULL);
- SPI_MasterTransferNonBlocking(EXAMPLE_SPI_MASTER, &handle, &xfer);
- while (masterFinished != true)
- {
- }
- /* Check if the data is right */
- for (i = 0; i < BUFFER_SIZE; i++)
- {
- if (srcBuff[i] != destBuff[i])
- {
- err++;
- PRINTF("The %d is wrong! data is %d\n\r", i, destBuff[i]);
- }
- }
- if (err == 0)
- {
- PRINTF("Succeed!\n\r");
- }
- while (1)
- {
- }
- }
复制代码
|
|