This is a complete listing of the RS-EDP software for the mbed module to support the RS-EDP platform.

Dependencies:   mbed

Committer:
DavidGilesHitex
Date:
Fri Nov 19 09:49:16 2010 +0000
Revision:
0:5b7639d1f2c4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidGilesHitex 0:5b7639d1f2c4 1 /* Driver for the MAX1x3x Serial ADC */
DavidGilesHitex 0:5b7639d1f2c4 2 /* ********************************* */
DavidGilesHitex 0:5b7639d1f2c4 3
DavidGilesHitex 0:5b7639d1f2c4 4 /* Version 2.00 */
DavidGilesHitex 0:5b7639d1f2c4 5 /* Last Ammend Date: 23/6/09 */
DavidGilesHitex 0:5b7639d1f2c4 6
DavidGilesHitex 0:5b7639d1f2c4 7
DavidGilesHitex 0:5b7639d1f2c4 8 #define _MAX1038_
DavidGilesHitex 0:5b7639d1f2c4 9
DavidGilesHitex 0:5b7639d1f2c4 10
DavidGilesHitex 0:5b7639d1f2c4 11
DavidGilesHitex 0:5b7639d1f2c4 12 /* Include Files Here */
DavidGilesHitex 0:5b7639d1f2c4 13 #include "mbed.h" /* mbed header file */
DavidGilesHitex 0:5b7639d1f2c4 14 #include "misra_types.h" /* MISRA Types header file */
DavidGilesHitex 0:5b7639d1f2c4 15 #include "defines.h"
DavidGilesHitex 0:5b7639d1f2c4 16 #include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */
DavidGilesHitex 0:5b7639d1f2c4 17
DavidGilesHitex 0:5b7639d1f2c4 18 #include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */
DavidGilesHitex 0:5b7639d1f2c4 19
DavidGilesHitex 0:5b7639d1f2c4 20
DavidGilesHitex 0:5b7639d1f2c4 21
DavidGilesHitex 0:5b7639d1f2c4 22
DavidGilesHitex 0:5b7639d1f2c4 23 /* Function Prototypes */
DavidGilesHitex 0:5b7639d1f2c4 24 sint32_t RSEDP_AM_Init_MAX1x3x(uint8_t I2C_addr) ;
DavidGilesHitex 0:5b7639d1f2c4 25 sint32_t RSEDP_AM_MAX103x_ReadChannel(uint8_t I2C_addr, uint8_t *uiResult, uint8_t uiChannel) ;
DavidGilesHitex 0:5b7639d1f2c4 26 sint32_t RSEDP_AM_MAX113x_ReadChannel(uint8_t I2C_addr, uint16_t *uiResult, uint8_t uiChannel) ;
DavidGilesHitex 0:5b7639d1f2c4 27
DavidGilesHitex 0:5b7639d1f2c4 28
DavidGilesHitex 0:5b7639d1f2c4 29
DavidGilesHitex 0:5b7639d1f2c4 30
DavidGilesHitex 0:5b7639d1f2c4 31
DavidGilesHitex 0:5b7639d1f2c4 32
DavidGilesHitex 0:5b7639d1f2c4 33 /* Reset and initialise MAX1x3x ADC */
DavidGilesHitex 0:5b7639d1f2c4 34 sint32_t RSEDP_AM_Init_MAX1x3x(uint8_t I2C_addr)
DavidGilesHitex 0:5b7639d1f2c4 35 {
DavidGilesHitex 0:5b7639d1f2c4 36 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 37 sint8_t uiSetup_byte = 0;
DavidGilesHitex 0:5b7639d1f2c4 38 sint8_t uiConfig_byte = 0;
DavidGilesHitex 0:5b7639d1f2c4 39 sint8_t uiMessage[3] = {0,0,0};
DavidGilesHitex 0:5b7639d1f2c4 40
DavidGilesHitex 0:5b7639d1f2c4 41
DavidGilesHitex 0:5b7639d1f2c4 42 /* Create Setup Byte for REST */
DavidGilesHitex 0:5b7639d1f2c4 43 uiSetup_byte = MAX1x3x_SETUP_RST | MAX1x3x_SETUP_REG;
DavidGilesHitex 0:5b7639d1f2c4 44
DavidGilesHitex 0:5b7639d1f2c4 45 /* Send Reset Command */
DavidGilesHitex 0:5b7639d1f2c4 46 Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiSetup_byte, 1) ;
DavidGilesHitex 0:5b7639d1f2c4 47
DavidGilesHitex 0:5b7639d1f2c4 48 /* Create Setup Byte */
DavidGilesHitex 0:5b7639d1f2c4 49 /* Internal reference always on and ADC11=analogue input and not Vref, Internal Clock */
DavidGilesHitex 0:5b7639d1f2c4 50 uiSetup_byte = MAX1x3x_SETUP_REG | MAX1x3x_SETUP_SEL_INT_Ref_AN11_AlwaysOn | MAX1x3x_SETUP_IntCLK | MAX1x3x_SETUP_UniPol | MAX1x3x_SETUP_NO_RST;
DavidGilesHitex 0:5b7639d1f2c4 51
DavidGilesHitex 0:5b7639d1f2c4 52 /* Create CONFIG Byte */
DavidGilesHitex 0:5b7639d1f2c4 53 /* Convert single ended unipolar, channel 0 initially */
DavidGilesHitex 0:5b7639d1f2c4 54 uiConfig_byte = MAX1x3x_CONFIG_REG | MAX1x3x_CONFIG_SingleEnded | MAX1x3x_CONFIG_ConvCh0 ;
DavidGilesHitex 0:5b7639d1f2c4 55
DavidGilesHitex 0:5b7639d1f2c4 56 uiMessage[0] = uiSetup_byte ;
DavidGilesHitex 0:5b7639d1f2c4 57 uiMessage[1] = uiConfig_byte ;
DavidGilesHitex 0:5b7639d1f2c4 58
DavidGilesHitex 0:5b7639d1f2c4 59 /* Send */
DavidGilesHitex 0:5b7639d1f2c4 60 if (Ack_Status == ACK)
DavidGilesHitex 0:5b7639d1f2c4 61 {
DavidGilesHitex 0:5b7639d1f2c4 62 Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, uiMessage, 2) ;
DavidGilesHitex 0:5b7639d1f2c4 63 }
DavidGilesHitex 0:5b7639d1f2c4 64 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 65 }
DavidGilesHitex 0:5b7639d1f2c4 66
DavidGilesHitex 0:5b7639d1f2c4 67
DavidGilesHitex 0:5b7639d1f2c4 68
DavidGilesHitex 0:5b7639d1f2c4 69
DavidGilesHitex 0:5b7639d1f2c4 70 /* Reads a single channel MAX103x I2C ADC passed as a parameter */
DavidGilesHitex 0:5b7639d1f2c4 71 /* returns a pointer to the 8-bit result */
DavidGilesHitex 0:5b7639d1f2c4 72 sint32_t RSEDP_AM_MAX103x_ReadChannel(uint8_t I2C_addr, uint8_t *uiResult, uint8_t uiChannel)
DavidGilesHitex 0:5b7639d1f2c4 73 {
DavidGilesHitex 0:5b7639d1f2c4 74 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 75 sint8_t uiConfig_byte = 0;
DavidGilesHitex 0:5b7639d1f2c4 76 sint8_t uiResult_value = 0;
DavidGilesHitex 0:5b7639d1f2c4 77 uint8_t uiCorrected_Channel = 0;
DavidGilesHitex 0:5b7639d1f2c4 78
DavidGilesHitex 0:5b7639d1f2c4 79
DavidGilesHitex 0:5b7639d1f2c4 80 /* Set which channel to convert */
DavidGilesHitex 0:5b7639d1f2c4 81 /* The pin out for MAX1038 is different from MAX1138 */
DavidGilesHitex 0:5b7639d1f2c4 82 /* The channel numbers 0-7 are reversed on the MAX1038. The PCB has been laid out for the MAX1138 */
DavidGilesHitex 0:5b7639d1f2c4 83 uiCorrected_Channel = uiChannel;
DavidGilesHitex 0:5b7639d1f2c4 84 if (uiChannel < 8)
DavidGilesHitex 0:5b7639d1f2c4 85 {
DavidGilesHitex 0:5b7639d1f2c4 86 uiCorrected_Channel = (7 - uiChannel);
DavidGilesHitex 0:5b7639d1f2c4 87 }
DavidGilesHitex 0:5b7639d1f2c4 88 uiConfig_byte = MAX1x3x_CONFIG_REG | MAX1x3x_CONFIG_SingleEnded | (uint8_t)(uiCorrected_Channel << 1) | MAX1x3x_CONFIG_SingleChannel ;
DavidGilesHitex 0:5b7639d1f2c4 89 Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiConfig_byte, 1) ;
DavidGilesHitex 0:5b7639d1f2c4 90
DavidGilesHitex 0:5b7639d1f2c4 91 /* Read Result */
DavidGilesHitex 0:5b7639d1f2c4 92 if (Ack_Status == ACK)
DavidGilesHitex 0:5b7639d1f2c4 93 {
DavidGilesHitex 0:5b7639d1f2c4 94 Ack_Status = CNTRL_I2C_Master_Mode_Receive(I2C_addr, &uiResult_value , 1) ;
DavidGilesHitex 0:5b7639d1f2c4 95 }
DavidGilesHitex 0:5b7639d1f2c4 96
DavidGilesHitex 0:5b7639d1f2c4 97
DavidGilesHitex 0:5b7639d1f2c4 98 /* Return result to caller */
DavidGilesHitex 0:5b7639d1f2c4 99 *uiResult = uiResult_value ;
DavidGilesHitex 0:5b7639d1f2c4 100 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 101 }
DavidGilesHitex 0:5b7639d1f2c4 102
DavidGilesHitex 0:5b7639d1f2c4 103
DavidGilesHitex 0:5b7639d1f2c4 104
DavidGilesHitex 0:5b7639d1f2c4 105
DavidGilesHitex 0:5b7639d1f2c4 106 /* Reads a single channel MAX113x I2C ADC passed as a parameter */
DavidGilesHitex 0:5b7639d1f2c4 107 /* returns a pointer to the 16-bit result */
DavidGilesHitex 0:5b7639d1f2c4 108 sint32_t RSEDP_AM_MAX113x_ReadChannel(uint8_t I2C_addr, uint16_t *uiResult, uint8_t uiChannel)
DavidGilesHitex 0:5b7639d1f2c4 109 {
DavidGilesHitex 0:5b7639d1f2c4 110 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 111 sint8_t uiConfig_byte = 0;
DavidGilesHitex 0:5b7639d1f2c4 112
DavidGilesHitex 0:5b7639d1f2c4 113 union BWL { sint8_t uiBytes[4] ; uint16_t uiWords[2] ; uint32_t uiLong ; } ;
DavidGilesHitex 0:5b7639d1f2c4 114 union BWL sResult ;
DavidGilesHitex 0:5b7639d1f2c4 115
DavidGilesHitex 0:5b7639d1f2c4 116
DavidGilesHitex 0:5b7639d1f2c4 117 /* Set which channel to convert */
DavidGilesHitex 0:5b7639d1f2c4 118 uiConfig_byte = MAX1x3x_CONFIG_REG | MAX1x3x_CONFIG_SingleEnded | (uint8_t)(uiChannel << 1) | MAX1x3x_CONFIG_SingleChannel ;
DavidGilesHitex 0:5b7639d1f2c4 119 Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiConfig_byte, 1) ;
DavidGilesHitex 0:5b7639d1f2c4 120
DavidGilesHitex 0:5b7639d1f2c4 121 /* Read Result */
DavidGilesHitex 0:5b7639d1f2c4 122 if (Ack_Status == ACK)
DavidGilesHitex 0:5b7639d1f2c4 123 {
DavidGilesHitex 0:5b7639d1f2c4 124 Ack_Status = CNTRL_I2C_Master_Mode_Receive(I2C_addr, &sResult.uiBytes[0] , 2) ;
DavidGilesHitex 0:5b7639d1f2c4 125 }
DavidGilesHitex 0:5b7639d1f2c4 126
DavidGilesHitex 0:5b7639d1f2c4 127 /* Return result to caller */
DavidGilesHitex 0:5b7639d1f2c4 128 *uiResult = sResult.uiWords[0] ;
DavidGilesHitex 0:5b7639d1f2c4 129 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 130 }
DavidGilesHitex 0:5b7639d1f2c4 131