Steven Kay
/
MCP9803_NUCLEO_Driver
Initial I2C Working
Diff: MCP9803/MCP9803.cpp
- Revision:
- 0:fbf82bf637bb
- Child:
- 1:444546e8cd20
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP9803/MCP9803.cpp Wed Mar 29 08:33:10 2017 +0000 @@ -0,0 +1,102 @@ +/******************************************************************************************** + + 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 + + *********************************************************************************************/ \ No newline at end of file