cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

RajKum
New Contributor

hello,

 

i have a maxrefdes117 which contains a max30102 heart rate sensor. the sensor has a very useful ready-made library built for arduino, but i want to use the sensor on psoc 6 ble. as far as i know, a similar library doesn't exist for psoc. i dont know much about this kind of stuff, except the very basics (i.e. i2c communication), so how would i proceed?

i found/made some functions to read/write from i2c registers, but dont really know how to proceed

static int8_t max30102Write(uint8_t dev_addr, uint8_t reg_addr, uint8_t* data, uint16_t len)
{
Cy_SCB_I2C_MasterSendStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, reg_addr, 0, &I2C_1_context);
for (int i = 0; i < len; i++)
{
Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, data[i], 0, &I2C_1_context);
}

Cy_SCB_I2C_MasterSendStop(I2C_1_HW, 0, &I2C_1_context);

return 0;
}
static int8_t max30102Read(uint8_t dev_addr, uint8_t reg_addr, uint8_t* data, uint16_t len)
{
Cy_SCB_I2C_MasterSendStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, reg_addr, 0, &I2C_1_context);
Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_READ_XFER, 0, &I2C_1_context);
for (int i = 0; i < len - 1; i++)
{
Cy_SCB_I2C_MasterReadByte(I2C_1_HW, CY_SCB_I2C_ACK, &data[i], 0, &I2C_1_context);
}
Cy_SCB_I2C_MasterReadByte(I2C_1_HW, CY_SCB_I2C_NAK, &data[len - 1], 0, &I2C_1_context);

Cy_SCB_I2C_MasterSendStop(I2C_1_HW, 0, &I2C_1_context);

return 0;
}
0 Likes
1 Solution
Rakshith
Moderator
Moderator

Hi @RajKum

You are correct, you will have to replace the I2C driver functions with PSoC 6 PDL or HAL APIs to interface the sensor.

Can you please let me know if you are using PSoC Creator or ModusToolbox? If in case you are using ModusToolbox, I believe you can use the HAL APIs directly for this application. Please refer to cyhal_i2c_master_mem_write() function. This can be used for maxim_max30102_write_reg() function and likewise the read API for the maxim_max30102_read_reg() function.

For HAL I2C initialization you can check this code snippet.

Thanks and Regards,
Rakshith M B

View solution in original post

0 Likes
1 Reply
Rakshith
Moderator
Moderator

Hi @RajKum

You are correct, you will have to replace the I2C driver functions with PSoC 6 PDL or HAL APIs to interface the sensor.

Can you please let me know if you are using PSoC Creator or ModusToolbox? If in case you are using ModusToolbox, I believe you can use the HAL APIs directly for this application. Please refer to cyhal_i2c_master_mem_write() function. This can be used for maxim_max30102_write_reg() function and likewise the read API for the maxim_max30102_read_reg() function.

For HAL I2C initialization you can check this code snippet.

Thanks and Regards,
Rakshith M B

View solution in original post

0 Likes
Top labels