Library Update: CAN and I2C
Version 24 of the library has gone live. Highlights are:
- CAN additions
- I2C Slave class
- I2C, Ethernet bugfixes
CAN
- The CAN class now has an attach() method, which is triggered on the reception of a CAN frame. This works in an identical manner to the attach() methods of other classes i.e. takes a function or member function which returns void, and has not parameters.
- In addition there is a new method called monitor(bool silent), which puts the CAN interface into silent monitor mode. When the interface is in monitor mode, it can receive messages, but it will not ACK them, and cannot transmit.
- Finally, the sampling point set by the frequency() method has been tweaked.
I2CSlave
#include I2CSlave slave(p9, p10); int main() { char buf[10]; char msg[] = "Slave!"; slave.address(0x30); while (1) { int i = slave.receive(); switch (i) { case I2CSlave::ReadAddressed: // Master has performed a read on the slave slave.write(msg, strlen(msg) + 1); // Includes null char break; case I2CSlave::WriteGeneral: // Master has performed a general call write slave.read(buf, 10); printf("Read G: %s\n", buf); break; case I2CSlave::WriteAddressed: // Master has performed an addressed write slave.read(buf, 10); printf("Read A: %s\n", buf); break; } for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer } }
I2C bugfix
Ethernet bugfix
Updating to the new Library
As usual, to get these updates for existing programs, simply click on the mbed library in your compiler project and choose "Update to latest revision!". New programs will automatically pull it in.
Any problems, suggestions or thumbs ups, please tell us in the Bugs/Suggestions forum!
You need to log in to post a comment