Namaskron Chimpalee
/
I2C_Master
master
Revision 6:e83f444edda0, committed 2018-12-17
- Comitter:
- maner1256
- Date:
- Mon Dec 17 18:01:55 2018 +0000
- Parent:
- 5:afb2d7fd50ad
- Commit message:
- master
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jun 23 18:11:39 2017 -0500 +++ b/main.cpp Mon Dec 17 18:01:55 2018 +0000 @@ -1,41 +1,40 @@ -/* mbed Example Program - * Copyright (c) 2006-2014 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ #include "mbed.h" - -// Read temperature from LM75BD -I2C i2c(I2C_SDA , I2C_SCL ); +I2C i2cMaster(D14,D15);// SDA, SCL +DigitalIn mybutton(USER_BUTTON); +Serial pc(USBTX, USBRX); +char writeData[6]; + +int main() { + + pc.baud(57600); + pc.printf("Starting I2CMaster\r\n"); + i2cMaster.frequency(400000); + int address ; + writeData[0]=0x01; + writeData[1]=0x02; + writeData[2]=0x03; + writeData[3]=0x04; + writeData[4]=0x05; + writeData[5]=0x06; -const int addr7bit = 0x48; // 7 bit I2C address -const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90 - -int main() { - char cmd[2]; - while (1) { - cmd[0] = 0x01; - cmd[1] = 0x00; - i2c.write(addr8bit, cmd, 2); - - wait(0.5); - - cmd[0] = 0x00; - i2c.write(addr8bit, cmd, 1); - i2c.read( addr8bit, cmd, 2); - - float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); - printf("Temp = %.2f\n", tmp); + while(1) { + int count = 0; + for (address=0; address<256; address+=2) { + if (!i2cMaster.write( address , NULL, 0)) { // 0 returned is ok + pc.printf("I2C address 0x%02X\r\n", address); + count++; + break; + } + pc.printf("I2C address 0x%02X\r\n", address); + if(mybutton == 0) { + + i2cMaster.write(address,writeData,6); + + pc.printf("i2cMaster Sent writeData[0] To 0x%02X \r\n", address); + wait(2); } -} \ No newline at end of file + + } + } + }