Gabriel Silva
/
mlx90615_lpc1768
program for temperature reading with mlx90615
smbus.cpp
- Committer:
- glsfacom
- Date:
- 2020-07-15
- Revision:
- 1:c0d057b08394
- Parent:
- 0:db513e91a2c9
File content as of revision 1:c0d057b08394:
#include "smbus.h" void smbus_start() { i2c.start(); } void smbus_stop() { i2c.stop(); } unsigned char smbus_send_byte(unsigned char byte) { return i2c.write(byte); } unsigned char smbus_send_address(unsigned char address, unsigned char rw) { unsigned char addr = address << 1; addr = addr + rw; return smbus_send_byte(addr); } unsigned char smbus_read_byte(unsigned char *status) { unsigned char byte; byte = i2c.read(i2c.ACK); return byte; } unsigned int smbus_read_uint(unsigned char *status, unsigned char read_mode){ unsigned char byte0, byte1, low, high, sts = 0; unsigned int value = 0x0000; byte0 = smbus_read_byte(&sts); *status = sts; if(*status != 0x8B) return 0; byte1 = smbus_read_byte(&sts); *status = sts; if(read_mode == BIG_ENDIAN){ high = byte0; low = byte1; } else{ high = byte1; low = byte0; } value |= low; value |= high<<8; return value; } unsigned char smbus_write_uint(unsigned char read_mode, unsigned int value){ unsigned char lsb, msb, byte0, byte1, status; lsb = value; msb = value >> 8; if(read_mode == BIG_ENDIAN){ byte0 = msb; byte1 = lsb; } else{ byte1 = msb; byte0 = lsb; } status = smbus_send_byte(byte0); if(!i2c.ACK) return status; status = smbus_send_byte(byte1); return status; }