Steven Kay
/
MCP9803_NUCLEO_Driver
Initial I2C Working
MCP9803/MCP9803.cpp
- Committer:
- sk398
- Date:
- 2017-03-29
- Revision:
- 0:fbf82bf637bb
- Child:
- 1:444546e8cd20
File content as of revision 0:fbf82bf637bb:
/******************************************************************************************** Filename: MCP9803.cpp Original Author: Steven Kay Development Group: Autonomous Systems Group, RAL Space Original Creation Date: April 2017 Description: <Desc> Revision History: Version 1.0 - Initial Release *********************************************************************************************/ #include "MCP9803.h" MCP9803::MCP9803(PinName sda, PinName scl, int Address, int frequency) { _I2C = new I2C(sda,scl); _I2C -> frequency(frequency); _I2C -> start(); _I2C -> stop(); chipAddress = Address; } int MCP9803::ConfigSensor() { return 0; } int MCP9803::I2C_Write(char *dataOut,int dataLen) { char outBuffer[dataLen]; for(int i=0 ; i<dataLen ; i++) { outBuffer[i] = *(dataOut+i); } int sendStatus = _I2C -> write(chipAddress,outBuffer,dataLen,0); return sendStatus; } char *MCP9803::I2C_Read(int dataLen) { char inBuffer[dataLen]; int receiveStatus = _I2C -> read(chipAddress,inBuffer,dataLen,0); if(receiveStatus != 0) { for(int i = 0; i < dataLen; i++) { inBuffer[i] = 0xFF - i; printf("Buffer Value = %02x",inBuffer[i]); } return inBuffer; } else { return inBuffer; } } /******************************************************************************************** Method: LinearMotor::LinearMotor Description: Class initialiser sets up the Linear Motor's pins Method Visibility: Public Input Arguments Name Type Description ----------------------------------------------------------------------------------------- pwmPin Int The integer number of the connected hardware pin for the PWM output to the linear motor sensorPin Int The integer number of the connected hardware pin for the Analog Sensor feedback from the Linear Motor Output Arguments ---------------------------------------------------------------------------------------- Name Type Description N/A *********************************************************************************************/