Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of minimal_i2c_mother by
master.cpp@1:92677fbab5f1, 2014-12-02 (annotated)
- Committer:
- rrbeauch
- Date:
- Tue Dec 02 17:41:35 2014 +0000
- Revision:
- 1:92677fbab5f1
- Parent:
- 0:d3bdf717512e
- Child:
- 2:4709985cf716
design day update
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nghansen | 0:d3bdf717512e | 1 | #include "mbed.h" |
| rrbeauch | 1:92677fbab5f1 | 2 | #define ROWSIZE (3) |
| rrbeauch | 1:92677fbab5f1 | 3 | #define SELECTSIZE (0x04) |
| nghansen | 0:d3bdf717512e | 4 | |
| rrbeauch | 1:92677fbab5f1 | 5 | //BusOut toCells(p5,p6,p7,p8,p9,p10,p11,p12); |
| rrbeauch | 1:92677fbab5f1 | 6 | //BusOut select(p13,p14,p15); |
| rrbeauch | 1:92677fbab5f1 | 7 | |
| nghansen | 0:d3bdf717512e | 8 | I2C Bus(p28, p27); |
| rrbeauch | 1:92677fbab5f1 | 9 | //I2CSlave Self(p9, p10); |
| rrbeauch | 1:92677fbab5f1 | 10 | |
| rrbeauch | 1:92677fbab5f1 | 11 | int slaveAddressRow1; |
| rrbeauch | 1:92677fbab5f1 | 12 | int slaveAddressRow2; |
| nghansen | 0:d3bdf717512e | 13 | |
| nghansen | 0:d3bdf717512e | 14 | Serial Usb(USBTX, USBRX); |
| rrbeauch | 1:92677fbab5f1 | 15 | char buffer[16] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x00}; |
| nghansen | 0:d3bdf717512e | 16 | int ack; |
| nghansen | 0:d3bdf717512e | 17 | |
| rrbeauch | 1:92677fbab5f1 | 18 | char slaveBuffer[16]; |
| nghansen | 0:d3bdf717512e | 19 | DigitalOut sent(LED1); |
| nghansen | 0:d3bdf717512e | 20 | DigitalOut received(LED2); |
| nghansen | 0:d3bdf717512e | 21 | |
| nghansen | 0:d3bdf717512e | 22 | void resetBus() |
| nghansen | 0:d3bdf717512e | 23 | { |
| nghansen | 0:d3bdf717512e | 24 | Bus.stop(); |
| nghansen | 0:d3bdf717512e | 25 | Bus.start(); |
| nghansen | 0:d3bdf717512e | 26 | return; |
| nghansen | 0:d3bdf717512e | 27 | } |
| nghansen | 0:d3bdf717512e | 28 | |
| nghansen | 0:d3bdf717512e | 29 | int main() |
| nghansen | 0:d3bdf717512e | 30 | { |
| rrbeauch | 1:92677fbab5f1 | 31 | slaveAddressRow1 = 0x02; |
| rrbeauch | 1:92677fbab5f1 | 32 | //slaveAddressRow2 = 0x04; |
| rrbeauch | 1:92677fbab5f1 | 33 | //Self.address(slaveAddressRow2); |
| nghansen | 0:d3bdf717512e | 34 | resetBus(); |
| nghansen | 0:d3bdf717512e | 35 | |
| nghansen | 0:d3bdf717512e | 36 | while (1) |
| nghansen | 0:d3bdf717512e | 37 | { |
| rrbeauch | 1:92677fbab5f1 | 38 | //for(int i = 0; i < sizeof buffer; buffer[i++]=0x00); |
| rrbeauch | 1:92677fbab5f1 | 39 | //Usb.scanf("%s", buffer); |
| rrbeauch | 1:92677fbab5f1 | 40 | //Usb.printf("%s \n\r", buffer); |
| rrbeauch | 1:92677fbab5f1 | 41 | |
| rrbeauch | 1:92677fbab5f1 | 42 | wait(1); |
| rrbeauch | 1:92677fbab5f1 | 43 | |
| rrbeauch | 1:92677fbab5f1 | 44 | int ack1 = Bus.write(slaveAddressRow1 & 0xFE, buffer, 16); |
| rrbeauch | 1:92677fbab5f1 | 45 | if(ack1 == 0) |
| rrbeauch | 1:92677fbab5f1 | 46 | Usb.printf("Row one sent\n\r"); |
| rrbeauch | 1:92677fbab5f1 | 47 | else |
| rrbeauch | 1:92677fbab5f1 | 48 | Usb.printf("No Ack"); |
| rrbeauch | 1:92677fbab5f1 | 49 | //ack2 = Bus.write(slaveAddressRow2 & 0xFE, buffer, 16); |
| rrbeauch | 1:92677fbab5f1 | 50 | //if(ack2 == 0) |
| rrbeauch | 1:92677fbab5f1 | 51 | // Usb.printf("Row two sent\n\r"); |
| nghansen | 0:d3bdf717512e | 52 | |
| rrbeauch | 1:92677fbab5f1 | 53 | /*int i = Bus.receive(); |
| rrbeauch | 1:92677fbab5f1 | 54 | switch (i) |
| rrbeauch | 1:92677fbab5f1 | 55 | { |
| rrbeauch | 1:92677fbab5f1 | 56 | case I2CSlave::ReadAddressed: |
| rrbeauch | 1:92677fbab5f1 | 57 | Bus.write(slaveBuffer, 16); |
| rrbeauch | 1:92677fbab5f1 | 58 | PC.printf("wrote: %s \n\r", buffer); |
| rrbeauch | 1:92677fbab5f1 | 59 | break; |
| rrbeauch | 1:92677fbab5f1 | 60 | case I2CSlave::WriteGeneral: |
| rrbeauch | 1:92677fbab5f1 | 61 | Bus.read(slaveBuffer, 16); |
| rrbeauch | 1:92677fbab5f1 | 62 | PC.printf("received broadcast: %s \n\r", buffer); |
| rrbeauch | 1:92677fbab5f1 | 63 | break; |
| rrbeauch | 1:92677fbab5f1 | 64 | case I2CSlave::WriteAddressed: |
| rrbeauch | 1:92677fbab5f1 | 65 | Bus.read(slaveBuffer, 16); |
| rrbeauch | 1:92677fbab5f1 | 66 | PC.printf("received message: %s \n\r", buffer); |
| rrbeauch | 1:92677fbab5f1 | 67 | break; |
| rrbeauch | 1:92677fbab5f1 | 68 | } |
| nghansen | 0:d3bdf717512e | 69 | |
| rrbeauch | 1:92677fbab5f1 | 70 | char cell = SELECTSIZE; |
| rrbeauch | 1:92677fbab5f1 | 71 | for(j = 0; j < ROWSIZE; j++) |
| rrbeauch | 1:92677fbab5f1 | 72 | { |
| rrbeauch | 1:92677fbab5f1 | 73 | toCells = buffer[j]; |
| rrbeauch | 1:92677fbab5f1 | 74 | select = cell; |
| rrbeauch | 1:92677fbab5f1 | 75 | cell >>= 1; |
| rrbeauch | 1:92677fbab5f1 | 76 | wait(0.1); |
| rrbeauch | 1:92677fbab5f1 | 77 | select = 0x00; |
| rrbeauch | 1:92677fbab5f1 | 78 | } |
| rrbeauch | 1:92677fbab5f1 | 79 | */ |
| nghansen | 0:d3bdf717512e | 80 | } |
| nghansen | 0:d3bdf717512e | 81 | } |
