I have no idea if this will work or not but you could try it rather than make your own I2C lib.
The following creates a new class SHT21_I2C which inherits the standard I2C. This new class adds 3 new methods:-
Try it and see if it works. Could save you some time :)
SHT21_I2C.h
/*
Copyright (c) 2010 Andy Kirkham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "mbed.h"
#ifndef SHT21_I2C_H
#define SHT21_I2C_H
class SHT_I2C : public I2C {
protected:
PinName _scl;
PinName _sda;
public:
SHT_I2C(PinName sda, PinName scl, const char *name = NULL) : I2C(sda, scl, name) {
_sda = sda;
_scl = scl;
}
void sclAsInput(void) {
switch(_scl) {
case p10:
LPC_PINCON->PINSEL0 &= ~(3UL << 2); // p10, P0.1 as GPIO
LPC_GPIO0->FIODIR &= ~(1UL << 1); // p10, P0.1 as Input
break;
case p27:
LPC_PINCON->PINSEL0&=~(3UL << 22); // p27, P0.11 as GPIO
LPC_GPIO0->FIODIR &= ~(1UL << 11); // p27, P0.11 as input
break;
}
}
int sclRead(void) {
switch(_scl) {
case p10: return (LPC_GPIO0->FIOPIN & (1UL << 1)) ? 1 : 0;
case p27: return (LPC_GPIO0->FIOPIN & (1UL << 11)) ? 1 : 0;
}
}
void sclNormal(void) {
switch(_scl) {
case p10:
LPC_PINCON->PINSEL0 &= ~(3UL << 2); // p10, P0.1 as I2C SCL1
LPC_PINCON->PINSEL0 |= (3UL << 2);
break;
case p27:
LPC_PINCON->PINSEL0 &= ~(3UL << 22); // p27, P0.11 as I2C SCL2
LPC_PINCON->PINSEL0 |= (2UL << 22);
break;
}
}
};
#endif
Hello all,
I am currently porting the Sensirion code for the SHT21 sensor to mbed. I have "No Hold Master" mode working just fine using the mbed I2C class and now I am working on the "Hold Master" mode. For this to work I need access to the sda and scl pins used by the I2C class on mbed so I can perform the following
"In the hold master mode, the SHT2x pulls down the SCL line while measuring to force the master into a wait state. By releasing the SCL line the sensor indicates that internal processing is terminated and that transmission may be continued."
I have tried something like
but no joy, the system hangs, not sure where yet.
Anyone have any suggestions?
Thanks, Serge