![](/media/cache/profiles/8138ec4f8dbf9991f277b91dd462de7d.jpg.50x50_q85.png)
Initial I2C Working
MCP9803/MCP9803.cpp
- Committer:
- sk398
- Date:
- 2017-03-29
- Revision:
- 1:444546e8cd20
- Parent:
- 0:fbf82bf637bb
- Child:
- 2:832cb4376d2a
File content as of revision 1:444546e8cd20:
/******************************************************************************************** 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; inBuffer = (char *)malloc(1); } 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) { setBufferSize(dataLen); int receiveStatus = _I2C -> read(chipAddress,inBuffer,dataLen,0); if(receiveStatus != 0) { for(int i = 0; i < dataLen; i++) { if(i % 2 == 0) { inBuffer[i] = 0xFF; } else { inBuffer[i] = 0x00; } printf("Buffer Value = %02x",inBuffer[i]); } return inBuffer; } else { return inBuffer; } } void MCP9803::setBufferSize(int dataLen) { inBuffer = (char *)realloc(inBuffer, dataLen); } char *MCP9803::getBuffer() { } void MCP9803::setBuffer() { } /******************************************************************************************** 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 *********************************************************************************************/