From 500ad4cbd47a5e6471b4855cf9360e5cf5d978ca Mon Sep 17 00:00:00 2001 From: r-studio Date: Wed, 28 Oct 2009 07:22:10 +0000 Subject: [PATCH] pretty code, minor improvements --- .../mulle/chips/ds2745/DS2745InternalC.nc | 29 ++++ .../mulle/chips/ds2745/DS2745InternalP.nc | 107 ++++++++++++++ .../chips/m16c62p/M16c62pAdcPlatformC.nc | 70 ++++++--- .../chips/m16c62p/M16c62pAdcPlatformP.nc | 59 ++++++++ .../mulle/chips/rf230/RF230SplitControlP.nc | 6 + tos/platforms/mulle/chips/rf230/RadioConfig.h | 2 +- tos/platforms/mulle/chips/rv8564/RV8564.nc | 36 ++++- tos/platforms/mulle/chips/rv8564/RV8564C.nc | 3 +- tos/platforms/mulle/chips/rv8564/RV8564P.nc | 139 +++++++++++++----- tos/platforms/mulle/chips/rv8564/rv8564.h | 3 +- .../mulle/softwarei2c/SoftI2CBusP.nc | 19 +-- 11 files changed, 393 insertions(+), 80 deletions(-) create mode 100644 tos/platforms/mulle/chips/ds2745/DS2745InternalC.nc create mode 100644 tos/platforms/mulle/chips/ds2745/DS2745InternalP.nc create mode 100644 tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformP.nc diff --git a/tos/platforms/mulle/chips/ds2745/DS2745InternalC.nc b/tos/platforms/mulle/chips/ds2745/DS2745InternalC.nc new file mode 100644 index 00000000..673f8900 --- /dev/null +++ b/tos/platforms/mulle/chips/ds2745/DS2745InternalC.nc @@ -0,0 +1,29 @@ +/** + * The DS2745 works well to be used with the DS2782 chip on the Mulle. + * + * @author Henrik Makitaavola + */ + +// TODO(henrik) Clean and comment this code better. Also Make the chip request +// access to the I2C bus instead of how its now that the program +// needs to request it. +configuration DS2745InternalC { + provides interface SplitControl; + provides interface Resource; + provides interface HplDS2745; +} + +implementation { + components MainC; + + components new SoftI2CBatteryMonitorRTCC() as I2C; + Resource = I2C; + + components new HplDS2745LogicP(0x68) as Logic; + MainC.SoftwareInit -> Logic; + Logic.I2CPacket -> I2C; + HplDS2745 = Logic; + + SplitControl = Logic; + +} diff --git a/tos/platforms/mulle/chips/ds2745/DS2745InternalP.nc b/tos/platforms/mulle/chips/ds2745/DS2745InternalP.nc new file mode 100644 index 00000000..e4845f4d --- /dev/null +++ b/tos/platforms/mulle/chips/ds2745/DS2745InternalP.nc @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2005-2006 Arch Rock Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of the Arched Rock Corporation nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE + */ + +/** + * + * @author Phil Buonadonna + * @version $Revision$ $Date$ + */ + +module DS2745InternalP { + provides interface HplDS2745[uint8_t id]; + uses interface HplDS2745 as ToHPLC; +} + +implementation { + uint8_t currentId; + + command error_t HplDS2745.setConfig[uint8_t id](uint8_t val) { + currentId = id; + return call ToHPLC.setConfig(val); + } + command error_t HplDS2745.measureTemperature[uint8_t id]() { + currentId = id; + return call ToHPLC.measureTemperature(); + } + command error_t HplDS2745.measureVoltage[uint8_t id]() { + currentId = id; + return call ToHPLC.measureVoltage(); + } + command error_t HplDS2745.measureCurrent[uint8_t id]() { + currentId = id; + return call ToHPLC.measureCurrent(); + } + command error_t HplDS2745.measureAccCurrent[uint8_t id]() { + currentId = id; + return call ToHPLC.measureAccCurrent(); + } + command error_t HplDS2745.setOffsetBias[uint8_t id](int8_t val) { + currentId = id; + return call ToHPLC.setOffsetBias(val); + } + command error_t HplDS2745.setAccOffsetBias[uint8_t id](int8_t val) { + currentId = id; + return call ToHPLC.setAccOffsetBias(val); + } + + async event void ToHPLC.setConfigDone(error_t error) { + signal HplDS2745.setConfigDone[currentId](error); + } + async event void ToHPLC.measureTemperatureDone(error_t result, uint16_t val) { + signal HplDS2745.measureTemperatureDone[currentId](result, val); + } + async event void ToHPLC.measureVoltageDone(error_t result, uint16_t val) { + signal HplDS2745.measureVoltageDone[currentId](result, val); + } + async event void ToHPLC.measureCurrentDone(error_t result, uint16_t val) { + signal HplDS2745.measureCurrentDone[currentId](result, val); + } + async event void ToHPLC.measureAccCurrentDone(error_t result, uint16_t val) { + signal HplDS2745.measureAccCurrentDone[currentId](result, val); + } + async event void ToHPLC.setOffsetBiasDone(error_t error) { + signal HplDS2745.setOffsetBiasDone[currentId](error); + } + async event void ToHPLC.setAccOffsetBiasDone(error_t error) { + signal HplDS2745.setAccOffsetBiasDone[currentId](error); + } + + default async event void HplDS2745.setConfigDone[uint8_t id]( error_t error ){ return; } + default async event void HplDS2745.measureTemperatureDone[uint8_t id]( error_t error, uint16_t val ){ return; } + default async event void HplDS2745.measureVoltageDone[uint8_t id]( error_t error, uint16_t val ){ return; } + default async event void HplDS2745.measureCurrentDone[uint8_t id]( error_t error, uint16_t val ){ return; } + default async event void HplDS2745.measureAccCurrentDone[uint8_t id]( error_t error, uint16_t val ){ return; } + default async event void HplDS2745.setOffsetBiasDone[uint8_t id]( error_t error ){ return; } + default async event void HplDS2745.setAccOffsetBiasDone[uint8_t id](error_t error){ return; } + +} + + diff --git a/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformC.nc b/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformC.nc index a22f4859..5765fbe2 100644 --- a/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformC.nc +++ b/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformC.nc @@ -1,28 +1,52 @@ -module M16c62pAdcPlatformC +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of Communication Group at Lulea University of Technology + * nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Mulle specific implementation of the M16c62pAdcPlatform interface. + * + * @author Henrik Makitaavola + */ +configuration M16c62pAdcPlatformC { provides interface M16c62pAdcPlatform; } implementation { - async command void M16c62pAdcPlatform.adcOn() - { - // turn on AVcc - PD7.BIT.PD7_6 = 1; - P7.BIT.P7_6 = 1; - - // turn on AVref - PD3.BIT.PD3_1 = 1; - P3.BIT.P3_1 = 1; - } - - async command void M16c62pAdcPlatform.adcOff() - { -// // turn off AVcc -// PD7.BIT.PD7_6 = 0; -// P7.BIT.P7_6 = 0; -// -// // turn off AVref -// PD3.BIT.PD3_1 = 0; -// P3.BIT.P3_1 = 0; - } -} \ No newline at end of file + components M16c62pAdcPlatformP, HplM16c62pGeneralIOC as IOs; + + M16c62pAdcPlatform = M16c62pAdcPlatformP; + M16c62pAdcPlatformP -> IOs.PortP76; +} diff --git a/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformP.nc b/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformP.nc new file mode 100644 index 00000000..02e7b620 --- /dev/null +++ b/tos/platforms/mulle/chips/m16c62p/M16c62pAdcPlatformP.nc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * - Neither the name of Communication Group at Lulea University of Technology + * nor the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD + * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Mulle specific implementation of the M16c62pAdcPlatform interface. + * + * @author Henrik Makitaavola + */ +module M16c62pAdcPlatformP +{ + provides interface M16c62pAdcPlatform; + uses interface GeneralIO VRef; +} +implementation +{ + async command void M16c62pAdcPlatform.adcOn() + { + call VRef.makeOutput(); + call VRef.set(); + } + + async command void M16c62pAdcPlatform.adcOff() + { + call VRef.clr(); + } +} diff --git a/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc b/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc index bd87661d..2f30cadf 100644 --- a/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc +++ b/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc @@ -50,16 +50,20 @@ implementation { command error_t SplitControl.start() { +#ifndef RF230_SLOW_SPI call SystemClockControl.minSpeed(M16C62P_PLL_CLOCK); +#endif return call SplitControlOrig.start(); } event void SplitControlOrig.startDone(error_t error) { +#ifndef RF230_SLOW_SPI if (error != SUCCESS) { call SystemClockControl.minSpeed(M16C62P_DONT_CARE); } +#endif signal SplitControl.startDone(error); } @@ -70,10 +74,12 @@ implementation event void SplitControlOrig.stopDone(error_t error) { +#ifndef RF230_SLOW_SPI if (error == SUCCESS) { call SystemClockControl.minSpeed(M16C62P_DONT_CARE); } +#endif signal SplitControl.stopDone(error); } } diff --git a/tos/platforms/mulle/chips/rf230/RadioConfig.h b/tos/platforms/mulle/chips/rf230/RadioConfig.h index 5ba89494..b3835f7c 100644 --- a/tos/platforms/mulle/chips/rf230/RadioConfig.h +++ b/tos/platforms/mulle/chips/rf230/RadioConfig.h @@ -64,7 +64,7 @@ #define __RADIOCONFIG_H__ #include - +#include "Timer.h" enum { diff --git a/tos/platforms/mulle/chips/rv8564/RV8564.nc b/tos/platforms/mulle/chips/rv8564/RV8564.nc index 16b492cd..3004be35 100755 --- a/tos/platforms/mulle/chips/rv8564/RV8564.nc +++ b/tos/platforms/mulle/chips/rv8564/RV8564.nc @@ -44,27 +44,27 @@ interface RV8564 /** * Turns the chip on. */ - async command void on(); + command error_t on(); /** * Turns the chip off. */ - async command void off(); + command error_t off(); /** * Checks if the chip is on. * * @return true if on. */ - async command bool isOn(); + command bool isOn(); /** * Enables/disables the interrupts generated by the CLKOUT. */ // TODO(henrik) This needs to be changed because there are different type of // interrupts generated by the chip. - async command void enableInterrupt(); - async command void disableInterrupt(); + command void enableInterrupt(); + command void disableInterrupt(); /** * Reads from a register. @@ -72,7 +72,7 @@ interface RV8564 * @param reg The register to be read. * @return The value of the register. */ - async command uint8_t readRegister(uint16_t reg); + command error_t readRegister(uint8_t reg); /** * Writes to a register. @@ -80,10 +80,30 @@ interface RV8564 * @param reg The register that is written to. * @param value The value that is written to the register. */ - async command void writeRegister(uint16_t reg, uint8_t value); - + command error_t writeRegister(uint8_t reg, uint8_t value); + + /** + * Signals when a register read finished. + * + * @param val The value read from the register. + * @param reg The register the value was read from. + */ + async event void readRegisterDone(uint8_t val, uint8_t reg); + + /** + * Signals when a register write finished. + * + * @param reg The register the value was written to. + */ + async event void writeRegisterDone(uint8_t reg); + /** * Signal when an interrupt occurs. */ async event void fired(); + + /** + * Enables CLKOUT from the RTC. + */ + command void enableCLKOUT(); } diff --git a/tos/platforms/mulle/chips/rv8564/RV8564C.nc b/tos/platforms/mulle/chips/rv8564/RV8564C.nc index 861b0535..1f484f9e 100755 --- a/tos/platforms/mulle/chips/rv8564/RV8564C.nc +++ b/tos/platforms/mulle/chips/rv8564/RV8564C.nc @@ -55,7 +55,8 @@ implementation Irq.HplM16c62pInterrupt -> Irqs.Int0; RTC = RTCP; - RTCP -> IOs.PortP47; + RTCP.CLKOE -> IOs.PortP47; + RTCP.CLKOUT -> IOs.PortP92; RTCP.GpioInterrupt -> Irq; RTCP.I2C -> I2C; RTCP.I2CResource -> I2C; diff --git a/tos/platforms/mulle/chips/rv8564/RV8564P.nc b/tos/platforms/mulle/chips/rv8564/RV8564P.nc index 77e594cb..9dcf0c2b 100755 --- a/tos/platforms/mulle/chips/rv8564/RV8564P.nc +++ b/tos/platforms/mulle/chips/rv8564/RV8564P.nc @@ -42,13 +42,13 @@ #include "rv8564.h" #include "I2C.h" -// TODO(henrik) The request to the I2C is done throuh a immediateRequest, this perhaps needs to be changed because -// its bad if the battery monitor has hold of the I2C bus. module RV8564P { provides interface RV8564 as RTC; // TODO(henrik) Exactly how is the RTC connected to mulle, what is the functionallity of GeneralIO? // Maybe there is only a init needed because the chip is always on? + uses interface GeneralIO as CLKOE; + uses interface GeneralIO as CLKOUT; uses interface GeneralIO; uses interface GpioInterrupt; uses interface I2CPacket as I2C; @@ -56,72 +56,139 @@ module RV8564P } implementation { - async command void RTC.on() + + enum + { + OFF, + IDLE, + READING, + WRITING + }; + norace uint8_t state = OFF; + norace uint8_t read_register; + uint8_t read_register_value; + uint8_t write_buffer[2]; + + command error_t RTC.on() { - call GeneralIO.makeOutput(); - call GeneralIO.set(); + if (state != OFF) + { + return SUCCESS; + } + state = IDLE; + return SUCCESS; } - async command void RTC.off() + command error_t RTC.off() { - call GeneralIO.clr(); - call GeneralIO.makeInput(); + if (state == OFF) + { + return SUCCESS; + } + else if (state != IDLE) + { + return FAIL; + } + call CLKOE.clr(); + call CLKOUT.clr(); + return SUCCESS; } - async command bool RTC.isOn() + command bool RTC.isOn() { - return (call GeneralIO.get() && call GeneralIO.isOutput()); + return ((state != OFF) ? true : false); } - async command void RTC.enableInterrupt() + command void RTC.enableCLKOUT() + { + call CLKOUT.makeInput(); + call CLKOUT.clr(); + call CLKOE.makeOutput(); + call CLKOE.set(); + } + command void RTC.enableInterrupt() { call GpioInterrupt.enableFallingEdge(); } - async command void RTC.disableInterrupt() + command void RTC.disableInterrupt() { call GpioInterrupt.disable(); } - - async command uint8_t RTC.readRegister(uint16_t reg) + + command error_t RTC.readRegister(uint8_t reg) { uint8_t val; - atomic + if (state != IDLE) + { + return FAIL; + } + state = READING; + read_register = reg; + call I2CResource.request(); + return SUCCESS; + } + + command error_t RTC.writeRegister(uint8_t reg, uint8_t value) + { + if (state != IDLE) { - if (call I2CResource.immediateRequest() == SUCCESS) + return FAIL; + } + state = WRITING; + write_buffer[0] = reg; + write_buffer[1] = value; + call I2CResource.request(); + return SUCCESS; + } + + event void I2CResource.granted() + { + atomic { + if (state == READING) { - call I2C.write(I2C_START, RV8564_WR_ADDR, 1, (uint8_t*)®); - call I2C.read(I2C_START | I2C_STOP, RV8564_RD_ADDR, 1, &val); - call I2CResource.release(); + call I2C.write(I2C_START, RV8564_ADDR, 1, &read_register); } - } - return val; + else if (state == WRITING) + { + call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, write_buffer); + } + } } - async command void RTC.writeRegister(uint16_t reg, uint8_t value) + async event void GpioInterrupt.fired() + { + signal RTC.fired(); + } + + async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) { - uint8_t wr[2] = {reg, value}; atomic { - if (call I2CResource.immediateRequest() == SUCCESS) + if (state == READING && data == &read_register_value) { - call I2C.write(I2C_START | I2C_STOP, RV8564_WR_ADDR, 2, wr); + state = IDLE; call I2CResource.release(); - } + signal RTC.readRegisterDone(read_register_value, read_register); + } } } - event void I2CResource.granted() + async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) { - // TODO(henrik) Insert communication code here. - } - - async event void GpioInterrupt.fired() - { - signal RTC.fired(); + if (state == READING) + { + call I2C.read(I2C_START | I2C_STOP, RV8564_ADDR, 1, &read_register_value); + } + else if (state == WRITING) + { + state = IDLE; + call I2CResource.release(); + signal RTC.writeRegisterDone(write_buffer[0]); + } } - default async event void RTC.fired() { } - async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {} - async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {} + default async event void RTC.readRegisterDone(uint8_t val, uint8_t reg) {} + default async event void RTC.writeRegisterDone(uint8_t reg) {} + default async event void RTC.fired() { } } diff --git a/tos/platforms/mulle/chips/rv8564/rv8564.h b/tos/platforms/mulle/chips/rv8564/rv8564.h index 48195ab7..e3563aeb 100755 --- a/tos/platforms/mulle/chips/rv8564/rv8564.h +++ b/tos/platforms/mulle/chips/rv8564/rv8564.h @@ -45,8 +45,7 @@ #define __RV8564_H__ /* constants */ -#define RV8564_WR_ADDR 0xa2 //slave address write 0xa2 or read 0xa3 -#define RV8564_RD_ADDR 0xa3 +#define RV8564_ADDR 0xa2 //slave address #define RV8564_CS1 0x00 diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc b/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc index 0460da4c..db5543b3 100755 --- a/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc +++ b/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc @@ -180,8 +180,14 @@ implementation } call I2CClk.clr(); - if (ack) call I2C.masterAck(); - else call I2C.masterNack(); + if (ack) + { + call I2C.masterAck(); + } + else + { + call I2C.masterNack(); + } } return retChar; } @@ -219,13 +225,6 @@ implementation transition(); call I2CClk.clr(); - // ...Check the ACK from the receiver.... - - // if(SDA2==1){ACK=0;} /* ACK received£¿*/ - // else ACK= 1; - - // SCL2 = LOW; - // transition(); idle(); } } @@ -234,6 +233,7 @@ implementation { atomic { + call I2CData.makeOutput(); call I2CClk.clr(); call I2CData.clr(); // Low for ack transition(); @@ -249,6 +249,7 @@ implementation { atomic { + call I2CData.makeOutput(); call I2CClk.clr(); call I2CData.set(); // High for nack -- 2.39.2