munny 0 Posted September 24, 2018 Share Posted September 24, 2018 Hello, I am trying to get RED, IR and GREEN led value in real time from MAX30101 sensor. I am using MSP430F5438A as my MCU. My IDE is CCS. The protocol required to communicate with the sensor is I2C. Now my problem is I am not any value except 0 in my read and write pointer (Indicated in the comment in my code). I am supposed to get some value in between 0 to 32. I'm attaching the link for the datasheet for the sensor: https://datasheets.maximintegrated.com/en/ds/MAX30101.pdf I know the datasheet is a whole lot. But I am referring page 17 which they have a pseudo code how to burst read the FIFO. If anyone already worked with the sensor or anyone know please have a look at it. #include <msp430.h> #include <msp430f5438a.h> #include <string.h> #define MAX30101_I2C_ADDRESS 0x57 #define MAX30101_REG_INT_STS1 0x00 #define MAX30101_REG_INT_STS2 0x01 #define MAX30101_REG_INT_EN1 0x02 #define MAX30101_REG_INT_EN2 0x03 #define MAX30101_REG_FIFO_WR 0x04 #define MAX30101_REG_FIFO_OVF 0x05 #define MAX30101_REG_FIFO_RD 0x06 #define MAX30101_REG_FIFO_DATA 0x07 #define MAX30101_REG_FIFO_CFG 0x08 #define MAX30101_REG_MODE_CFG 0x09 #define MAX30101_REG_SPO2_CFG 0x0a #define MAX30101_REG_LED1_PA 0x0c #define MAX30101_REG_LED2_PA 0x0d #define MAX30101_REG_LED3_PA 0x0e #define MAX30101_REG_PILOT_PA 0x10 #define MAX30101_REG_MULTI_LED 0x11 #define MAX30101_REG_TINT 0x1f #define MAX30101_REG_TFRAC 0x20 #define MAX30101_REG_TEMP_CFG 0x21 #define MAX30101_REG_PROX_INT 0x30 void Clock_setup(); // default void MAX30101_setup(); // Sensor config setup void I2C_setup(); void sendByte(char register_add, char data); int readByte(char wr_add, char rd_add, char register_add); void burstRead(char wr_add, char rd_add, char register_add, int no_ofsample); void FIFO_Clear(); char LED1 [96]; char LED2 [96]; char LED3 [96]; long L1[32]; long L2[32]; long L3[32]; int wr; int rd; int Ns; // number of available sample void main() { WDTCTL = WDTPW + WDTHOLD; Clock_setup(); I2C_setup(); _EINT(); MAX30101_setup(); while(1){ //FIFO_Clear(); wr= readByte(0xAE, 0xAF, 0x04); // reading WR_PTR---> I don't know why getting zero rd= readByte(0xAE, 0xAF, 0x06); // reading RD_PTR---> I don't know why getting zero Ns = wr-rd; if(Ns<0){ Ns+=32; } if(wr != rd){ burstRead(0xAE, 0xAF, 0x07, Ns); } } } void Clock_setup(){ P11DIR |= BIT2; // check smclk, 1MHz default P11SEL |= BIT2; // check smclk, 1MHz default P11DIR |= BIT0; // check aclk, 32.8KHz default P11SEL |= BIT0; // check aclk, 32.8KHz default } void I2C_setup() { P3SEL |= BIT7; // P3.1(UCB0_SDA), P3.2(UCB0_SCL) P5SEL |= BIT4; UCB1CTL1 |= UCSWRST; // reset enable UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // master + I2C mode + Sync UCB1CTL1 = UCSSEL_2 + UCSWRST; //use SMCLK + still reset UCB1BR0 = 10; // default SMCLK 1M/10 = 100KHz.........? UCB1BR1 = 0; // UCB1I2CSA = MAX30101_I2C_ADDRESS; // MAX30101 7 bit address 0x57 UCB1CTL1 &= ~UCSWRST; // reset clear // UCB1IE |= UCTXIE + UCRXIE; //TX and RX interrupt enabled } //Single Byte Transmit (TX) void sendByte(char register_add, char data){ // UCB0I2CSA = slave_add; //slave address for transmit mode UCB1CTL1 |= UCTR + UCTXSTT; // I2C transmit (write) mode + generating START condition UCB1TXBUF = register_add; //register address to measure temperature/pressure while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent while(UCB1CTL1 & UCTXSTT); //wait till START condition is cleared UCB1TXBUF = data; //send data to register while(!(UCB1IFG & UCTXIFG)); //wait until data got sent UCB1CTL1 |= UCTXSTP; //generate a STOP condition while(UCB1CTL1 & UCTXSTP); //wait until stop condition got sent } //Single Byte Receive (RX) int readByte(char wr_add, char rd_add, char register_add){ int rx_byte; //UCB0I2CSA = slave_add; //slave address UCB1CTL1 |= UCTXSTT + UCTR; // Generating START + I2C transmit (write) UCB1TXBUF = wr_add; //write register address while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent UCB1TXBUF = register_add; //write register address while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent while( UCB1CTL1 & UCTXSTT); //wait till START condition is cleared UCB1CTL1 |= UCTXSTT; //generate RE-START //UCB1I2CSA = slave_add; //slave address UCB1TXBUF = rd_add; //write register address while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent UCB1CTL1 &=~ UCTR; //receive mode while( UCB1CTL1 & UCTXSTT); //wait till START condition is cleared rx_byte = UCB1RXBUF; //read byte UCB1CTL1 |= UCTXSTP; //generate stop condition while(UCB1CTL1 & UCTXSTP); //wait till stop condition got sent return rx_byte; } //Multiple Byte Receive (RX) void burstRead(char wr_add, char rd_add, char register_add, int no_ofsample){ unsigned int i; //UCB1I2CSA = slave_add; //slave address //while(!(UCB1IFG & UCTXIFG)); //wait until slave address got sent UCB1CTL1 |= UCTXSTT + UCTR; // Generating START condition + I2C transmit (write) UCB1TXBUF = wr_add; //write register address while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent UCB1TXBUF = register_add; //write register address while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent while( UCB1CTL1 & UCTXSTT); //wait till START condition is cleared UCB1CTL1 |= UCTXSTT; //generate RE-START condition //UCB1I2CSA = slave_add; //slave address UCB1TXBUF = rd_add; //write register address while(!(UCB1IFG & UCTXIFG)); //wait until reg address got sent UCB1CTL1 &=~ UCTR; //receive mode while( UCB1CTL1 & UCTXSTT); //wait till START condition is cleared //buffer[0] = UCB1RXBUF; //dummy read //while(!(UCB1IFG & UCRXIFG)); //wait till byte is completely read for(i=0;i<no_ofsample;++i){ LED1 = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED1[i+1] = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED1[i+2] = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read L1= ((LED1 << 16) | (LED1[i+1] << 08 | LED1[i+2]) & 0x03FFFF; LED2 = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED2[i+1] = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED2[i+2] = UCB1RXBUF; //burst read L2= ((LED2 << 16) | (LED2[i+1] << 08 | LED2[i+2]) & 0x03FFFF; while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED3 = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED3[i+1] = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read LED3[i+2] = UCB1RXBUF; //burst read while(!(UCB1IFG & UCRXIFG)); //wait while the Byte has being read L3= ((LED3 << 16) | (LED3[i+1] << 08 | LED3[i+2]) & 0x03FFFF; } //buffer[no_ofBytes-1] = UCB1RXBUF; //last Byte read //while(!(UCB1IFG & UCRXIFG)); //wait UCB1CTL1 |= UCTXSTP; //generate stop condition //while(UCB1CTL1 & UCTXSTP); //wait till stop condition got sent } // Sample Average = 4 // Mode = MultiLED // ADC Range = 2048 // Sample rate = 400 //pulse width = 411 // active slot 01, 02 and 03 void MAX30101_setup(){ sendByte(0x08, 0x40); sendByte(0x09, 0x07); sendByte(0x0A, 0x0F); sendByte(0x11, 0x77); sendByte(0x12, 0x07); } void FIFO_Clear(){ sendByte(0x04, 0x00); sendByte(0x05, 0x00); sendByte(0x06, 0x00); } Thanks, Rowshon. Quote Link to post Share on other sites
mph 10 Posted September 24, 2018 Share Posted September 24, 2018 I suspect you will get more help if you could provide a detailed description as to why the code is not doing what you expect. Is this code known to work or are you developing it yourself? I had to dig through the 30101 data sheet to understand the purpose of the various registers and functions. If the read and write pointers are stuck on zero, which is what you have indicated, that means they are not advancing with each iteration of the while loop. It looks like you are attempting to do a data register burst read in each iteration; the data sheet explicitly instructs not to do this. Perhaps if you replace the burst read with a byte read; see if that changes the pointer counters. Quote Link to post Share on other sites
munny 0 Posted September 24, 2018 Author Share Posted September 24, 2018 38 minutes ago, mph said: I suspect you will get more help if you could provide a detailed description as to why the code is not doing what you expect. Is this code known to work or are you developing it yourself? I had to dig through the 30101 data sheet to understand the purpose of the various registers and functions. If the read and write pointers are stuck on zero, which is what you have indicated, that means they are not advancing with each iteration of the while loop. It looks like you are attempting to do a data register burst read in each iteration; the data sheet explicitly instructs not to do this. Perhaps if you replace the burst read with a byte read; see if that changes the pointer counters. Hello mph, Thank you for your time and response. I'll follow the instruction you have given and will let you know if that works. So I read the burst read case in the datasheet but confused seeing the pseudo-code format on page 17. In that code, they read all the sample available at a time. I am sorry for not being more clear. I am trying to develop the code from scratch. At his point my concern is reading RED, IR and GREEN LED data in real time. I am going to implement UART to observe the data. But as I am stuck in getting the number of available samples to read, that's why I trim my code and omit the UART part for now. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.