Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. /**
  2.  * @defgroup adc ADC driver
  3.  * @code #include <drivers/adc/adc.h> @endcode
  4.  *
  5.  * @brief Simple driver for external LTC2450 delta/sigma ADC.
  6.  *
  7.  * This is a slightly hard-coded driver that assumes an
  8.  * LTC2450 ADC is connected via USART in SPI-mode, using
  9.  * pins PD4, PD0 and CS on PD7. Later to be improved and
  10.  * more generalized!
  11.  *
  12.  * @author  Jimmy Myhrman
  13.  * @date    2010-05-17
  14.  */
  15.  
  16. /**@{*/
  17.  
  18. #ifndef LTC2450_H_
  19. #define LTC2450_H_
  20.  
  21. /*-----------------------------------------------
  22.  * Definitions
  23.  * ---------------------------------------------*/
  24.  
  25. // LTC2450 pins
  26. #define SPI_PORT    PORTD
  27. #define SPI_PIN     PIND
  28. #define SPI_DDR     DDRD
  29. #define SPI_SCK     PD4
  30. #define SPI_MISO    PD0
  31. #define SPI_CS      PD7
  32.  
  33. #define LTC2450_SELECT()   ( SPI_PORT &= ~(1<<SPI_CS) )
  34. #define LTC2450_UNSELECT() ( SPI_PORT |=  (1<<SPI_CS) )
  35.  
  36.  
  37. /*-----------------------------------------------
  38.  * Inclusions
  39.  * ---------------------------------------------*/
  40. #include <stdlib.h>
  41. #include <inttypes.h>
  42.  
  43.  
  44. /*-----------------------------------------------
  45.  * Function Prototypes
  46.  * ---------------------------------------------*/
  47.  
  48. /**
  49.  * @brief Initialize LTC2450 connection.
  50.  *
  51.  * Initializes the USART module on AVR to be used in SPI-mode.
  52.  * A single read operation is also performed in order to clear
  53.  * out any old sample in the LTC2450 ADC.
  54.  */
  55. void ltc2450_init(void);
  56.  
  57. /**
  58.  * @brief Reads the latest ADC value.
  59.  *
  60.  * Reads the previously sampled value from the LTC2450 and
  61.  * immediately starts a new conversion. Each conversion takes
  62.  * approx 30ms. In case this function is called at a higher
  63.  * frequency, the returned data will be 0xFFFF. This indicates
  64.  * that ADC is busy, and user is responsible for reading until
  65.  * valid sample has been retrieved.
  66.  *
  67.  * @retval
  68.  *      The latest sample. 0xFFFF in case ADC is busy.
  69.  */
  70. uint16_t ltc2450_read(void);
  71.  
  72. /**@}*/
  73. #endif
  74.  
  75.