COSA
An Object-Oriented Platform for Arduino Programming
PCF8591 Class Reference

#include <PCF8591.hh>

Inheritance diagram for PCF8591:
Inheritance graph
Collaboration diagram for PCF8591:
Collaboration graph

Public Types

enum  {
  AIN0 = 0x00, AIN1 = 0x01, AIN2 = 0x02, AIN3 = 0x03,
  CHANNEL_MASK = 0x03, AUTO_INCREMENT = 0x04, FOUR_INPUTS = 0x00, THREE_DIFF_INPUTS = 0x10,
  TWO_MIXED_INPUTS = 0x20, TWO_DIFF_INPUTS = 0x30, OUTPUT_ENABLE = 0x40
}
 

Public Member Functions

 PCF8591 (uint8_t addr=0)
 
bool begin (uint8_t cntl)
 
void end ()
 
uint8_t sample ()
 
uint8_t sample (uint8_t cntl)
 
int sample (uint8_t *buf, uint8_t size)
 
bool convert (uint8_t value)
 

Private Member Functions

bool is_async () const
 
void sync_request ()
 
void async_request ()
 
virtual void on_completion (uint8_t type, int count)
 

Private Attributes

uint8_t m_addr
 
bool m_async
 

Detailed Description

Driver for the PCF8591 2-Wire 8-bit A/D and D/A converter.

Circuit

PCF8591 module with potentiometer, photoresistor and thermistor.

+------------+
(POT)---[ ]---------1-|AIN0 VCC|-16--------------(VCC)
(PHR)---[ ]---------2-|AIN1 AOUT|-15-------------(AOUT)
(THM)---[ ]---------3-|AIN2 VREF|-14--------------(VCC)
(AIN3)--------------4-|AIN3 AGND|-13--------------(GND)
(GND)---------------5-|A0 EXT|-12--------------(GND)
(GND)---------------6-|A1 OSC|-11
(GND)---------------7-|A2 SCL|-10-----------(SCL/A5)
(GND)---------------8-|GND SDA|-9------------(SDA/A4)
+------------+

References

  1. Philips Semiconductor product description (Rev. 2003 Jan 27).

Definition at line 48 of file PCF8591.hh.

Member Enumeration Documentation

anonymous enum

Control byte; selection of input channel and mode of operation Fig. 5 Control byte, pp. 6.

Enumerator
AIN0 
AIN1 
AIN2 
AIN3 
CHANNEL_MASK 
AUTO_INCREMENT 
FOUR_INPUTS 
THREE_DIFF_INPUTS 
TWO_MIXED_INPUTS 
TWO_DIFF_INPUTS 
OUTPUT_ENABLE 

Definition at line 54 of file PCF8591.hh.

Constructor & Destructor Documentation

PCF8591::PCF8591 ( uint8_t  addr = 0)
inline

Construct PCF8591 TWI A/D, D/A converter device access to given chip address.

Parameters
[in]addrchip address (0..7)

Definition at line 73 of file PCF8591.hh.

Member Function Documentation

bool PCF8591::begin ( uint8_t  cntl)

Begin a sampling sequence for the channel given by the control parameter. Return true(1) if successful otherwise false(0).

Parameters
[in]cntlcontrol byte
Returns
bool

Definition at line 24 of file PCF8591.cpp.

bool PCF8591::convert ( uint8_t  value)

Convert given value to analog output (voltage). Return true(1) if successful otherwise false(0).

Parameters
[in]valueoutput value.
Returns
bool

Definition at line 34 of file PCF8591.cpp.

void PCF8591::end ( )
inline

End sampling sequence.

Definition at line 89 of file PCF8591.hh.

uint8_t PCF8591::sample ( )
inline

Sample the channel defined by the latest begin() call. Return sample value.

Returns
sample

Definition at line 99 of file PCF8591.hh.

uint8_t PCF8591::sample ( uint8_t  cntl)
inline

Sample the given channel and return converted value.

Parameters
[in]cntlcontrol byte
Returns
sample

Definition at line 112 of file PCF8591.hh.

int PCF8591::sample ( uint8_t *  buf,
uint8_t  size 
)
inline

Read a sequence of samples the channel defined by the latest begin() call.

Parameters
[in]bufsample buffer.
[in]sizeof sample buffer.
Returns
count or negative error code.

Definition at line 128 of file PCF8591.hh.


The documentation for this class was generated from the following files: