aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2018-08-12 10:35:23 +0300
committerAvi Levkovich <avi@twine-s.com>2018-08-12 10:35:23 +0300
commitccec0abb96ce3cfc7c0d75a78e371cef90e2b968 (patch)
tree75d8c065908351f6acafd8214e16b62819fe1881 /Software/Embedded_SW/Embedded
parent85f396d49c44fedae0a3af776143978d1a497154 (diff)
downloadTango-ccec0abb96ce3cfc7c0d75a78e371cef90e2b968.tar.gz
Tango-ccec0abb96ce3cfc7c0d75a78e371cef90e2b968.zip
Add ADC_MUX module to read the mid tank pressure sensor
Diffstat (limited to 'Software/Embedded_SW/Embedded')
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c137
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h16
2 files changed, 153 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c
new file mode 100644
index 000000000..87e41726f
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c
@@ -0,0 +1,137 @@
+/*
+ * ADC_MUX.c
+ *
+ * Created on: Aug 12, 2018
+ * Author: avi
+ *
+ * Mid tank pressure sensor. Bosch 02612300215
+ */
+#include <stdint.h>
+#include <stdbool.h>
+#include "include.h"
+#include "inc/hw_memmap.h"
+#include "inc/hw_types.h"
+#include "inc/tm4c1294ncpdt.h"
+#include "driverlib/gpio.h"
+#include "driverlib/pin_map.h"
+#include "driverlib/rom.h"
+#include "driverlib/rom_map.h"
+#include "driverlib/sysctl.h"
+#include "driverlib/i2c.h"
+#include "Drivers/I2C_Communication/I2C_Switch/I2C_Swith.h"
+#include "drivers/I2C_Communication/I2C.h"
+
+#include "ADC_MUX.h"
+
+double MidTank_Pressure[8];
+
+uint32_t I2C_ADC_Config(uint32_t I2C_Slave_Add,uint32_t channel )
+{
+ uint32_t Status = OK;
+
+ uint8_t Config_Buf[3];
+
+ Config_Buf[0] = 0x00;
+ Config_Buf[1] = channel;
+ Config_Buf[2] = 0x80;
+
+ Status = I2C_Write(MUX_I2C_BASE, I2C_Slave_Add, Config_Buf, 3);
+
+ return Status;
+}
+
+uint32_t I2C_ADC_Set_For_Read_Ch(uint32_t I2C_Slave_Add )
+{
+ uint32_t Status = OK;
+
+ uint8_t SetRead = 0x02;
+
+ Status = I2C_Write(MUX_I2C_BASE, SetRead, SetRead, 1);
+
+ return Status;
+}
+
+
+uint32_t I2C_ADC_Read_Ch(uint32_t I2C_Slave_Add )
+{
+ uint32_t VsampleInBits = 0,temp;
+
+ uint8_t No_BytesToRead = 2;
+
+ uint8_t I2C_Read_buf[2] = {0,0};
+
+ I2C_Read(MUX_I2C_BASE, I2C_Slave_Add, *I2C_Read_buf, No_BytesToRead );
+
+ temp = (I2C_Read_buf[0] << 8) | I2C_Read_buf[1];
+
+ VsampleInBits=temp & 0x0fff;
+
+ return VsampleInBits;
+}
+
+uint32_t Calculate_Pressure(uint32_t VsampleInBits )
+{
+ double Pressure = 0;
+
+
+
+
+ return Pressure;
+}
+
+uint32_t Read_MidTank_Pressure_Sensor(uint32_t MidTank_ID)
+{
+ uint32_t Status = OK;
+ uint32_t I2C_Slave_Add;
+ uint32_t Channel;
+ uint32_t VsampleInBits;
+
+ switch(MidTank_ID)
+ {
+ case 1:
+ I2C_Slave_Add = 0x44;
+ Channel = 0x20;
+ break;
+ case 2:
+ I2C_Slave_Add = 0x44;
+ Channel = 0x08;
+ break;
+ case 3:
+ I2C_Slave_Add = 0x46;
+ Channel = 0x80;
+ break;
+ case 4:
+ I2C_Slave_Add = 0x46;
+ Channel = 0x20;
+ break;
+ case 5:
+ I2C_Slave_Add = 0x44;
+ Channel = 0x10;
+ break;
+ case 6:
+ I2C_Slave_Add = 0x44;
+ Channel = 0x04;
+ break;
+ case 7:
+ I2C_Slave_Add = 0x46;
+ Channel = 0x40;
+ break;
+ case 8:
+ I2C_Slave_Add = 0x46;
+ Channel = 0x10;
+ break;
+ default:
+ break;
+ }
+
+ Status = I2C_ADC_Config(I2C_Slave_Add, Channel);
+ Status = I2C_ADC_Set_For_Read_Ch(I2C_Slave_Add);
+ VsampleInBits = I2C_ADC_Read_Ch(I2C_Slave_Add);
+
+ MidTank_Pressure[MidTank_ID -1] = Calculate_Pressure(VsampleInBits);
+
+ return Status;
+}
+
+
+
diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h
new file mode 100644
index 000000000..8852eef41
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h
@@ -0,0 +1,16 @@
+/*
+ * ADC_MUX.h
+ *
+ * Created on: Aug 12, 2018
+ * Author: avi
+ */
+
+#ifndef DRIVERS_I2C_COMMUNICATION_ADC_MUX_ADC_MUX_H_
+#define DRIVERS_I2C_COMMUNICATION_ADC_MUX_ADC_MUX_H_
+
+
+uint32_t Read_MidTank_Pressure_Sensor(uint32_t MidTank_ID);
+
+#define MUX_I2C_BASE 2
+
+#endif /* DRIVERS_I2C_COMMUNICATION_ADC_MUX_ADC_MUX_H_ */