MPR121 i2c touch keypad with Wire library
szilvasyz Sun Aug 13, 2017 11:08 am
(I am a new member here, so excuse me if my problem is not relevant here. If so, please write me, where to discuss my problem, thanks.)
Last two days I have tried to use a touch keypad assembled with MPR121 chip with my “blue pill” generic STM32 board (STM32F103C8T6). As I saw there is an Adafruit library to handle this hardware, but unforunatelly compiling that library runs into an error. The error comes up because there is no “endTransmission(uint8)” method in the STM32’s Wire library.
Looking after this special use of “endTransmission()” in the Adafruit library I found that the library closes the transmission the way the stop condition is not to be sent (“endTransmission(false)”) at the end of register addressing.
Further investigations showed me that with STM32’s Wire library I can communicate with other i2c devices (I tried PCF8574 and DS1621) without any problem. Reading the datasheet of MPR121 I found that there is a special communication protocol case that seems cannot be realized using STM32 Wire library.
Reading a register from MPR121 needs a communication as follows:
1. sending start condition
2. sending slave address for write mode
3. reading slave ACK
4. sending register address
5. reading slave ACK
6. SENDING REPEATED START CONDITION
7. sending slave address for read mode
8. reading slave ACK
9. reading data byte (register cotent)
10. sending master NAK
11. sending stop condition
I could not make the sequence above using STM32 Wire library. The most critical point of the sequence is step 6, sending a repeated start condition; if you send a stop condition followed by a start condition instead, you would not read the desired register data but always get zero in step 9.
Yesterday evening I wrote a bit-banging i2c communication sketch that could send a repeated start condition at step 6 and I could read all the registers of MPR121 correctly.
Maybe there is a method to generate the sequence above with Wire lib but it is unknown for me. If so, please write me how to do!
At this point – if I am right and the desired sequence cannot be assembled by STM32 Wire lib – I cannot decide what would be the best solution:
– writing my own bit-banging code for handling this HW?
– modifying STM32 Wire library for myself to handle endTransmission(false) calls corectly?
– putting a request (where, how?) to modify Wire library as above?
Please help me for solution. Thank you in advance.
Regards,
Zoltan
