Hello,
i am working on a project to measure and display ecg data on a pc GUI .
I am using ADAS 1000 and pic 24fj64gb002. I have been struggling with the code as it refuse to build.
Its been generating errors when building with Mplabx.
I will like advice on what mistake I am making.
Please find below the code I am working on.
Thanks
Tolu
[
/*
* File: ecgmain.c
* Author: TolU
*
* Created on 07 December 2014, 01:31
*/
/*********************INCLUDE FILES LIST **************************/
#include "p24FJ64GB002.h
#include "xc.h"
#include "PPS.h"
#include "spi.h"
#include "ADAS1000.h"
//ADAS1000 CHIP SELECT PIN INTIALIZATION
#define ADAS_CS_TRIS TRISBbits.TRISB2 = 0 //Chip Select an output on RB2 pin
#define ADAS_CS PORTBbits.RB2 //Chip Select on RB2 pin
/***************ADAS1000 SPI FUNCTION DEFINITIONS ******************/
void ADAS_SPI_ENABLE()
{
SPI1STATbits.SPIEN = 1; //ENABLE SPI1
}
void ADAS_SPI_DISABLE()
{
SPI1STATbits.SPIEN = 0; //DISABLE SPI1
}
void ADAS_PPS_INIT()
{
__builtin_write_OSCCONL(OSCCON & 0xBF); //Unlock Registers
RPINR20bits.SDI1R = 7; //SDI1 on RP07 PIN16
RPOR5bits.RP10R = 7; //SDO1 on RP10 PIN21
RPOR5bits.RP11R = 8; //SCK1 on RP11 PIN22
__builtin_write_OSCCONL(OSCCON | 0x40); //Lock Registers
}
void ADAS_SPI_INIT()
{
ADAS_PPS_INIT();
//ADAS1000 SPI1 COMM CONFIGURATION
ADAS_SPI_DISABLE(); //Disable SPI Port
SPI1BUF = 0; //Clear SPI Buffer
IFS0bits.SPI1IF = 0; //Clear Interrupt Flag
IEC0bits.SPI1IE = 0; //DISABLE INTERRUPT
SPI1STATbits.SPIROV = 0;//Clear OverFlow Bit
SPI1CON1 = 0x033F;
/*SPI1CON1 SETTINGS*//*
Internal SPI CLK enabled, SDOx pin controlled by module, 8-bit comm,
Data_in sampled at end of output time, SDO changes on Active to Idle clock,
SSx pin not used,Idle clock state is low, Master Mode, Sec=1:1, Pri=1:1*/
SPI1CON2 = 0x0000;
/*SPI1CON2 SETTINGS*//*
Framed SPI disabled, Frame sync pulse output, Frame sync pulse active low,
Frame sync pulse before first bit clock, enhance buffer diabled*/
ADAS_SPI_ENABLE(); //ENABLE SPI PORT
}
/**************ADAS1000 FUNCTION DEFINITIONS *********************/
void ENABLE_ADAS()
{
ADAS_CS = 0; //SELECT ADAS1000 CHIP
}
void DISABLE_ADAS()
{
ADAS_CS = 1; //DESELECT ADAS1000 CHIP
}
void ADAS_ECGCTL_INIT()
{
ADAS_SPI_INIT(); //READY ADAS-MCU SPI COMMUNICATION
ENABLE_ADAS(); //ENABLE ADAS1000 SPI COMMUNICATION
WriteSPI1(ECGCTL1); //WRITE 4-BYTE CMD TO ECGCTL CONTROL REGISTER
WriteSPI1(ECGCTL2);
WriteSPI1(ECGCTL3);
WriteSPI1(ECGCTL4);
ReadSPI1(); //READ SPI1BUF TO CLEAR FLAGS
DISABLE_ADAS(); //DISBALE ADAS1000 SPI COMMUNICATION
}
void ADAS_FRMCTL_INIT()
{
ADAS_SPI_INIT(); //READY ADAS-MCU SPI COMMUNICATION
ENABLE_ADAS(); //ENABLE ADAS1000 SPI COMMUNICATION
WriteSPI1(FRMCTL1); //WRITE 4-BYTE CMD TO FRMCTL CONTROL REGISTER
WriteSPI1(FRMCTL2);
WriteSPI1(FRMCTL3);
WriteSPI1(FRMCTL4);
ReadSPI1(); //READ SPI1BUF TO CLEAR FLAGS
DISABLE_ADAS(); //DISBALE ADAS1000 SPI COMMUNICATION
}
void ADAS_INIT()
{
ADAS_ECGCTL_INIT();
ADAS_FRMCTL_INIT();
}
void ADAS_READ_DATA()
{
ADAS_SPI_INIT();
//SEND ADAS1000 READ COMMAND
ENABLE_ADAS();
WriteSPI1(FRAMES1);
WriteSPI1(FRAMES2);
WriteSPI1(FRAMES3);
WriteSPI1(FRAMES4);
DISABLE_ADAS();
//READ ADAS1000 HEADER DATA
ENABLE_ADAS();
HEADER_RX[1] = ReadSPI1(SPI1BUF);
HEADER_RX[2] = ReadSPI1(SPI1BUF);
HEADER_RX[3] = ReadSPI1(SPI1BUF);
HEADER_RX[4] = ReadSPI1(SPI1BUF);
DISABLE_ADAS();
//READ ADAS1000 Left Arm (LA) DATA
ENABLE_ADAS();
LA_RX[1] = ReadSPI1(SPI1BUF);
LA_RX[2] = ReadSPI1(SPI1BUF);
LA_RX[3] = ReadSPI1(SPI1BUF);
LA_RX[4] = ReadSPI1(SPI1BUF);
DISABLE_ADAS();
//READ ADAS1000 Left Leg (LL) DATA
ENABLE_ADAS();
LL_RX[1] = ReadSPI1(SPI1BUF);
LL_RX[2] = ReadSPI1(SPI1BUF);
LL_RX[3] = ReadSPI1(SPI1BUF);
LL_RX[4] = ReadSPI1(SPI1BUF);
DISABLE_ADAS();
//READ ADAS1000 Right Arm (RA) DATA
ENABLE_ADAS();
RA_RX[1] = ReadSPI1(SPI1BUF);
RA_RX[2] = ReadSPI1(SPI1BUF);
RA_RX[3] = ReadSPI1(SPI1BUF);
RA_RX[4] = ReadSPI1(SPI1BUF);
DISABLE_ADAS();
ADAS_SPI_DISABLE();
]
On building I got the following errors.
[EC2.c:70:11: error: 'ECGCTL1' undeclared (first use in this function)
EC2.c:70:11: note: each undeclared identifier is reported only once for each function it appears in
EC2.c:71:11: error: 'ECGCTL2' undeclared (first use in this function)
EC2.c:72:11: error: 'ECGCTL3' undeclared (first use in this function)
EC2.c:73:11: error: 'ECGCTL4' undeclared (first use in this function)
EC2.c: In function 'ADAS_FRMCTL_INIT':
EC2.c:81:1: warning: statement with no effect
EC2.c:81:11: error: expected ';' before 'FRMCTL'
EC2.c:82:1: warning: statement with no effect
EC2.c:82:11: error: expected ';' before 'FRMCTL'
EC2.c:83:1: warning: statement with no effect
EC2.c:83:11: error: expected ';' before 'FRMCTL'
EC2.c:84:1: warning: statement with no effect
EC2.c:84:11: error: expected ';' before 'FRMCTL'
EC2.c: In function 'ADAS_READ_DATA':
EC2.c:98:11: error: 'FRAMES1' undeclared (first use in this function)
EC2.c:99:11: error: 'FRAMES2' undeclared (first use in this function)
EC2.c:100:11: error: 'FRAMES3' undeclared (first use in this function)
EC2.c:101:11: error: 'FRAMES4' undeclared (first use in this function)
EC2.c:105:1: error: 'HEADER_RX' undeclared (first use in this function)
EC2.c:112:1: error: 'LA_RX' undeclared (first use in this function)
EC2.c:119:1: error: 'LL_RX' undeclared (first use in this function)
EC2.c:126:1: error: 'RA_RX' undeclared (first use in this function)
EC2.c:131:1: error: expected declaration or statement at end of input
make[2]: *** [build/default/production/EC2.o] Error 255
make[2]: *** Waiting for unfinished jobs....
nbproject/Makefile-default.mk:108: recipe for target 'build/default/production/EC2.o' failed
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory 'C:/Users/TOLUWALOPE/Desktop/ECO/EC.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/TOLUWALOPE/Desktop/ECO/EC.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 11s)]