This blog is related to my blog - 'Blog #5 : Taking Mikroe ECG Click from Prototyping to Medical Grade ECG Click'. In this blog, I am submitting working codes (not pseduo codes) but incomplete as today is an extended deadline date. I cannot do testing as I need to address personal works & court works also, and I still have to write proper code but this is only how I work or would do work if given project, this is still away 4-7 months (with additional components/project costing)for the proper implementation of the proposed idea.
1. Power Supplies needed for ECG 2 Click
- LCD 16 x 2 : 5 VDC
- LCD MiniClick : 5VDC
- ECG 2 Click : 5 VDC
- Microchip SAM E51 Curiosity Nano Evaluation Kit : powered by USB
For 5 VDC, I have used AVNET's Ultra96V2G along with 'click Megazzine click 2', which gives 5VDC as external adapter got damaged.You can use any other power source.
Caution : If one is connecting LCD Miniclick like I have done, do not connect both 5V and 3.3 V power supplies and batteries to 'Curiosity Nano Base', as here when I did, it caused minor accident- burning and melting of wires.
When LCD Miniclick is supplied with only 1 voltage, it works fine, and neither boards- Curiosity Nano nor LCD Miniclick nor click Megazzine click got any damage.
So, melting of Part-1 of the proposal got demonstrated, bad joke
2. Hardware SetUp
The pin description with Microchip SAM E51 Curiosity Nano Evaluation Kit are already explained in blog 5.
The ECG2 Click pins are inserted in mikroBUS Click socket of the Curiosity Nano, which also has Microchip SAM E51 Curiosity Nano. There are 2 LCDs both will display the reading.
The Infineon AIROC will be used to transfer to AWS IoT Cloud and Android Applet. The LED will blink with different frequencies, while doing this.
The LCD code- Miniclick and 16x2 of this blog is same for Blog 11.
The AWS IoT Cloud code is in blog 9.
The Android applet code is in blog 8.
3. Code : Moving Towards Clinical Grade ECG2 Click
One need not do so much programming, as the APIs may be available, anyway I m taking hard route for this experiment. This is the same code on which I will work on if given project.
//Author : Mr. Abhishek Bansal
//Company: New Era Consultancy Services
typedef enum
{
HEART_BYTE1 = 0,
HEART_BYTE2,
HEART_BYTE3,
HEART_BYTE4,
HEART_BYTE5,
HEART_BYTE6,
HEART_BYTE7,
HEART_BYTE8,
HEART_BYTE9,
HEART_BYTE10,
HEART_BYTE11,
HEART_BYTE12,
HEART_BYTE13,
HEART_BYTE14,
HEART_BYTE15,
HEART_RBYTE
HEART_RREAD,
}HEART_RATE_PSTE;
typedef enum
{
SPI_CLOCK_PHASE_TRAILING_EDGE = SERCOM_SPIM_CTRLA_CPHA_TRAILING_EDGE,
SPI_CLOCK_PHASE_LEADING_EDGE = SERCOM_SPIM_CTRLA_CPHA_LEADING_EDGE,
SPI_CLOCK_PHASE_INVALID = 0xFFFFFFFFU
} SPI_CLOCK_MASTER;
typedef enum
{
SPI_CLOCK_POLARITY_IDLE_LOW = SERCOM_SPIM_CTRLA_CPOL_IDLE_LOW,
SPI_CLOCK_POLARITY_IDLE_HIGH = SERCOM_SPIM_CTRLA_CPOL_IDLE_HIGH,
SPI_CLOCK_POLARITY_INVALID = 0xFFFFFFFFU
} SPI_CLOCK_MASTER_POLARITY;
typedef enum
{
SPI_DATA_BITS_8 = SERCOM_SPIM_CTRLB_CHSIZE_8_BIT,
SPI_DATA_BITS_9 = SERCOM_SPIM_CTRLB_CHSIZE_9_BIT,
SPI_DATA_BITS_INVALID = 0xFFFFFFFFU
} SPI_MASTER_DATA_BITS;
typedef struct
{
uint32_t clockFrequency;
SPI_CLOCK_PHASE clockPhase;
SPI_CLOCK_POLARITY clockPolarity;
SPI_DATA_BITS dataBits;
} SPI_MASTER_TRANSFER_SETUP;
typedef void (*SERCOM_SPI_Heart1_CALLBACK)(uintptr_t context);
sercom1SPIObj.callback = NULL ;
sercom1SPIObj.transferIsBusy = false ;
sercom1SPIObj.txSize = 0U;
sercom1SPIObj.rxSize = 0U;
SERCOM1_REGS->SPIM.SERCOM_CTRLB = SERCOM_SPIM_CTRLB_CHSIZE_8_BIT | SERCOM_SPIM_CTRLB_RXEN_Msk ;
while((SERCOM1_REGS->SPIM.SERCOM_SYNCBUSY) != 0U) { }
SERCOM1_REGS->SPIM.SERCOM_BAUD = (uint8_t)SERCOM_SPIM_BAUD_BAUD(SERCOM1_SPIM_BAUD_VALUE);
static void mem_copy(volatile void* pDst, volatile void* pSrc, uint32_t nBytes)
{
volatile uint8_t* pSource = (volatile uint8_t*)pSrc;
volatile uint8_t* pDest = (volatile uint8_t*)pDst;
for (uint32_t i = 0U; i < nBytes; i++)
{
pDest[i] = pSource[i];
}
}
volatile static uint8_t lead3_1_ReadBuf[SERCOM0_SPI_READ_BUFFER_SIZE];
volatile static uint8_t lead3_1_WriteBuf[SERCOM0_SPI_WRITE_BUFFER_SIZE];
#define SPI_lead3_1ERROR_NONE 0U
#define SPI_lead3_1_BUFOVF SERCOM_SPIS_STATUS_BUFOVF_Msk
typedef uint32_t SPI_lead3_1_ERROR;
volatile static uint8_t lead3_2_ReadBuf[SERCOM0_SPI_READ_BUFFER_SIZE];
volatile static uint8_t lead3_2_WriteBuf[SERCOM0_SPI_WRITE_BUFFER_SIZE];
#define SPI_lead3_2ERROR_NONE 0U
#define SPI_lead3_2_BUFOVF SERCOM_SPIS_STATUS_BUFOVF_Msk
typedef uint32_t SPI_lead3_2_ERROR;
volatile static uint8_t lead3_3_ReadBuf[SERCOM0_SPI_READ_BUFFER_SIZE];
volatile static uint8_t lead3_3_WriteBuf[SERCOM0_SPI_WRITE_BUFFER_SIZE];
#define SPI_lead3_3ERROR_NONE 0U
#define SPI_lead3_3_BUFOVF SERCOM_SPIS_STATUS_BUFOVF_Msk
typedef uint32_t SPI_lead3_3_ERROR;
volatile static uint8_t lead3_4_ReadBuf[SERCOM0_SPI_READ_BUFFER_SIZE];
volatile static uint8_t lead3_4_WriteBuf[SERCOM0_SPI_WRITE_BUFFER_SIZE];
#define SPI_lead3_4ERROR_NONE 0U
#define SPI_lead3_4_BUFOVF SERCOM_SPIS_STATUS_BUFOVF_Msk
typedef uint32_t SPI_lead3_4_ERROR;