Skip to main content
RShiv.1
Associate III
December 16, 2021
Question

capacitive touch CPT112s interface with STM32 using I2C not working

  • December 16, 2021
  • 15 replies
  • 4588 views

Hi,

As we were trying to interface CPT112s capacitive touch controller with STM32 using I2C,

we were able to get the I2C working...but I was not able to get touch event (either 1 or any high value)

Below is my address reference for both device and memory.

uint16_t DevAddress1 = 0xC0<<1;

uint16_t MemAddress1 = 0xC0200000;

uint8_t mac_id_buf[6] = "";

char print_msg[100] = "";

 

if(HAL_OK == HAL_I2C_IsDeviceReady(&hi2c1,DevAddress1,200,2000)){

if(HAL_OK == HAL_I2C_Mem_Read(&hi2c1,DevAddress1,MemAddress1,I2C_MEMADD_SIZE_8BIT,(uint8_t*)&mac_id_buf[0],0x0006,HAL_MAX_DELAY)) {

strcpy(print_msg,"SUCCESS HAL_I2C_Mem_Read\r\n");

HAL_UART_Transmit(&huart5,(uint8_t*)print_msg,strlen(print_msg),1000);

sprintf(print_msg,"%X %X %X %X %X %X\r\n", mac_id_buf[0],mac_id_buf[1],mac_id_buf[2],mac_id_buf[3],mac_id_buf[4],mac_id_buf[5]);

HAL_UART_Transmit(&huart5,(uint8_t*)print_msg,strlen(print_msg),1000);

}

else{

strcpy(print_msg,"ERROR in HAL_I2C_Mem_Read()\r\n");

}

}

else{

strcpy(print_msg,"ERROR in HAL_I2C_IsDeviceReady()\r\n");

}

Kindly let me know what changes needed to be done so that I can get the capactive sense value .

Thanks and regards

Ravi chandra

This topic has been closed for replies.

15 replies

TDK
December 16, 2021

Does HAL_I2C_IsDeviceReady return HAL_OK?

> uint16_t DevAddress1 = 0xC0<<1;

Not sure what the slave address is, but this overflows 8 bits, so that can't be correct.

> uint16_t MemAddress1 = 0xC0200000;

This also overflows. The compiler will give you a warning about this one.

../Core/Src/main.c:83:26: warning: conversion from 'unsigned int' to 'uint16_t' {aka 'short unsigned int'} changes value from '3223322624' to '0' [-Woverflow]

"If you feel a post has answered your question, please click ""Accept as Solution""."
RShiv.1
RShiv.1Author
Associate III
December 22, 2021

Hi ,

yes HAL_I2C_IsDeviceReady is returning HAL_OK.

The I2C read for similar MACID read worked for us with

uint16_t DevAddress1 = 0x50<<1;

uint16_t MemAddress1 = 0xFA;

But here the issue with CPT112S silicon chip is according to their data sheet it say I2Cslave address+touch event+reg_index+reserved bit which is 32 bits

so how do we consider this and access the mem address of the I2C slave for us to sense the capacitive touch of each event??

attached is the data sheet for reference..Kindly let us know how do we proceed to get the capacitive touch to work,

Thanks

Ravi

RShiv.1
RShiv.1Author
Associate III
December 22, 2021

Hi ,

for > uint16_t DevAddress1 = 0xC0<<1; No warning from the compiler

for  uint16_t MemAddress1 = 0xC0200000; I got the warning

but when I changed to  uint32_t MemAddress1 = 0xC0200000; No warning seen

but output is not seen as we point to the actual Mem address

Kindly let me know

Thanks

Ravi 

TDK
December 22, 2021

for > uint16_t DevAddress1 = 0xC0<<1; No warning from the compiler

Why would there be? It doesn't overflow 16 bits. But when you pass it as an 8-bit slave address, the upper bits get cut off.

Just because the compiler doesn't have any warnings doesn't mean your code is correct.

The datasheet says you should read 3 bytes for each event. So read 3 bytes with HAL_I2C_Master_Read and interpret it.

I see nothing in the datasheet which suggests there are memory addresses in the chip.

"If you feel a post has answered your question, please click ""Accept as Solution""."
RShiv.1
RShiv.1Author
Associate III
December 22, 2021

Hi,

attached is the code which I am using to flash the hex file and test.according to data sheet page 18 it says touch event as 32 bits(I2C_slave address+ packetcounter_event type+ CSxx_index + reserved bits).

you HAL_I2C_Mem_Read will read the memaddress from the slave address that is C0<<1 that is the reason I2C is passing..what should be the configurable Memaddress so that we could the touch event bit/byte changing to 1 ..Kindly let us know..

Thanks

Ravi

RShiv.1
RShiv.1Author
Associate III
December 23, 2021

Hi TDK,

Any update on my previous post..kindly let me know how we can procees to check the capacitive touch output.

thanks

Ravi

TDK
December 23, 2021

As I said in my last post, read 3 bytes using HAL_I2C_Master_Read to get the data. HAL_I2C_Mem_Read is not what you want here.

0xC0 << 1 still overflows on 8 bits. I don't know what the correct slave address is as it's not in the datasheet. Looks like you have different values in different places in the code.

>       uint16_t DevAddress1 = 0xC0<<1;

>       uint16_t DevAddress = 0x50 << 1;

"If you feel a post has answered your question, please click ""Accept as Solution""."
RShiv.1
RShiv.1Author
Associate III
December 24, 2021

Hi,

 uint16_t DevAddress1 = 0xC0<<1; this address works for I2C interface and it is passing I am seeing any warning as such..As you said the datasheet does not give the slave address...we found through some github code where silicon labs had used simliar address and we tried and this worked...but not able to see the capactive touch values..

will we get some high value like 0xFF when the touch happens or will we get 0 for CS_00 reg,1 for CS_01 reg and so on??...

what I needed address is for Memaddress ??....did you mention 0x50 for memaddress??...let me know

Thanks

Ravi

RShiv.1
RShiv.1Author
Associate III
December 24, 2021

Hi ,

As I understand there is no HAL_I2C_Master_Read in the stml4xx_hal_i2c.c...its HAL_I2C_Master_Receive...I tried using this..looks like from the data sheet the CPT has something called as event base buffer interface..we might have to connect one more pin for event ..so that I2C buffer when full will indicate and we can store the value.

Just let us know if this is on right path.

Thanks

Ravi

TDK
December 24, 2021
Yes, I meant HAL_I2C_Master_Receive.
I'm not sure how I can assist any more without actually writing your code for you. Perhaps there is someone physically closer to you who can help with the basics.
"If you feel a post has answered your question, please click ""Accept as Solution""."
RShiv.1
RShiv.1Author
Associate III
December 28, 2021

Hi,

I do not want any assistance in writing the code as we are doing it from our side...it more that we wanted to see if you had come across CPT112S chip so that we can get the address issue resolved.we got the I2C working and rest of our module ourselves...nothing to worry.

Thanks and regards

Ravi