Continued work on MAX5715. MACRO functions are done, mostly tested in logic analyzer. SPI unable to work with hardware SS, so software SS is used instead
Added UART3 on PB10/PB11 for terminal (future use) git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@225 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -32,45 +32,101 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "spi.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
#define MAX5715_NUMBER_OF_DACS (4)
|
||||
|
||||
#define MAX5715_SEL_DACA (0x0)
|
||||
#define MAX5715_SEL_DACB (0x1)
|
||||
#define MAX5715_SEL_DACC (0x2)
|
||||
#define MAX5715_SEL_DACD (0x4)
|
||||
#define MAX5715_SPI_MAX_CLK_HZ (50000000)
|
||||
// SPI settings
|
||||
#define MAX5715_SPI_Direction (SPI_Direction_1Line_Tx)
|
||||
#define MAX5715_SPI_Mode (SPI_Mode_Master)
|
||||
#define MAX5715_SPI_DataSize (SPI_DataSize_8b)
|
||||
#define MAX5715_SPI_CPOL (SPI_CPOL_Low)
|
||||
#define MAX5715_SPI_CPHA (SPI_CPHA_1Edge)
|
||||
#define MAX5715_SPI_NSS (SPI_NSS_Soft)
|
||||
#define MAX5715_SPI_NSS_INTERNAL (SPI_NSSInternalSoft_Reset)
|
||||
#define MAX5715_SPI_FirstBit (SPI_FirstBit_MSB)
|
||||
#define MAX5715_SPI_CRCPolynomial (7)
|
||||
#define MAX5715_SPI_RX_QUEUE (1)
|
||||
#define MAX5715_SPI_TX_QUEUE (32)
|
||||
|
||||
#define MAX5715_CMD_CODEn (0x00)
|
||||
#define MAX5715_CMD_LOADn (0x10)
|
||||
#define MAX5715_CMD_CODEn_LOAD_ALL (0x20)
|
||||
#define MAX5715_CMD_CODEn_LOADn (0x30)
|
||||
#define MAX5715_CMD_POWER_NORMAL (0x40)
|
||||
#define MAX5715_CMD_POWER_PD1K (0x41)
|
||||
#define MAX5715_CMD_POWER_PD100K (0x42)
|
||||
#define MAX5715_CMD_POWER_HIGHZ (0x43)
|
||||
#define MAX5715_CMD_SW_CLEAR (0x50)
|
||||
#define MAX5715_CMD_SW_RESET (0x51)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_ON (0x60)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_OFF (0x61)
|
||||
#define MAX5715_CMD_REF_DAC_EXT (0x70)
|
||||
#define MAX5715_CMD_REF_DAC_2V5 (0x71)
|
||||
#define MAX5715_CMD_REF_DAC_2V0 (0x72)
|
||||
#define MAX5715_CMD_REF_DAC_4V0 (0x73)
|
||||
#define MAX5715_CMD_REF_ON_EXT (0x74)
|
||||
#define MAX5715_CMD_REF_ON_2V5 (0x75)
|
||||
#define MAX5715_CMD_REF_ON_2V0 (0x76)
|
||||
#define MAX5715_CMD_REF_ON_4V0 (0x77)
|
||||
#define MAX5715_CMD_CODE_ALL (0x80)
|
||||
#define MAX5715_CMD_LOAD_ALL (0x81)
|
||||
#define MAX5715_CMD_CODE_ALL_LOAD_ALL (0x82)
|
||||
#define MAX5715_SEL_DACA (0x1)
|
||||
#define MAX5715_SEL_DACB (0x2)
|
||||
#define MAX5715_SEL_DACC (0x4)
|
||||
#define MAX5715_SEL_DACD (0x8)
|
||||
|
||||
#define MAX5715_CMD_CODEn (0x00)
|
||||
#define MAX5715_CMD_LOADn (0x10)
|
||||
#define MAX5715_CMD_CODEn_LOAD_ALL (0x20)
|
||||
#define MAX5715_CMD_CODEn_LOADn (0x30)
|
||||
#define MAX5715_CMD_POWER_NORMAL (0x40)
|
||||
#define MAX5715_CMD_POWER_PD1K (0x41)
|
||||
#define MAX5715_CMD_POWER_PD100K (0x42)
|
||||
#define MAX5715_CMD_POWER_HIGHZ (0x43)
|
||||
#define MAX5715_CMD_SW_CLEAR (0x50)
|
||||
#define MAX5715_CMD_SW_RESET (0x51)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_ON (0x60)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_OFF (0x61)
|
||||
#define MAX5715_CMD_REF_DAC_EXT (0x70)
|
||||
#define MAX5715_CMD_REF_DAC_2V5 (0x71)
|
||||
#define MAX5715_CMD_REF_DAC_2V0 (0x72)
|
||||
#define MAX5715_CMD_REF_DAC_4V0 (0x73)
|
||||
#define MAX5715_CMD_REF_ON_EXT (0x74)
|
||||
#define MAX5715_CMD_REF_ON_2V5 (0x75)
|
||||
#define MAX5715_CMD_REF_ON_2V0 (0x76)
|
||||
#define MAX5715_CMD_REF_ON_4V0 (0x77)
|
||||
#define MAX5715_CMD_CODE_ALL (0x80)
|
||||
#define MAX5715_CMD_LOAD_ALL (0x81)
|
||||
#define MAX5715_CMD_CODE_ALL_LOAD_ALL (0x82)
|
||||
|
||||
|
||||
#define MAX5715_writeCODEn(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn | (0x0F & DAC)), DATA))
|
||||
#define MAX5715_writeLOADn(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_LOADn | (0x0F & DAC)), 0x0000))
|
||||
#define MAX5715_writeCODEnLOADALL(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn_LOAD_ALL | (0x0F & DAC)), DATA))
|
||||
#define MAX5715_writeCODEnLOADn(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn_LOADn | (0x0F & DAC)), DATA))
|
||||
|
||||
#define MAX5715_writePOWER_NORMAL(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_NORMAL), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writePOWER_PD1K(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_PD1K), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writePOWER_PD100K(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_PD100K), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writePOWER_HIGHZ(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_HIGHZ), (0x00FF & (DAC << 4))))
|
||||
|
||||
#define MAX5715_writeSW_CLEAR(self) (MAX5715_sendCommand(self, (MAX5715_CMD_SW_CLEAR), 0x0000))
|
||||
#define MAX5715_writeSW_RESET(self) (MAX5715_sendCommand(self, (MAX5715_CMD_SW_RESET), 0x0000))
|
||||
|
||||
#define MAX5715_writeCONFIG_LATCH_ON(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_CONFIG_LATCH_ON), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeCONFIG_LATCH_OFF(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_CONFIG_LATCH_OFF), (0x00FF & (DAC << 4))))
|
||||
|
||||
#define MAX5715_writeREF_DAC_EXT(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_EXT), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_DAC_2V5(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_2V5), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_DAC_2V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_2V0), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_DAC_4V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_4V0), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_EXT(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_EXT), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_2V5(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_2V5), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_2V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_2V0), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_4V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_4V0), (0x00FF & (DAC << 4))))
|
||||
|
||||
#define MAX5715_writeCODE_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODE_ALL), DATA))
|
||||
#define MAX5715_writeLOAD_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_LOAD_ALL), 0x0000))
|
||||
#define MAX5715_writeCODE_ALL_LOAD_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODE_ALL_LOAD_ALL), DATA))
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct MAX5715_DAC
|
||||
{
|
||||
uint8_t id;
|
||||
uint16_t value;
|
||||
};
|
||||
|
||||
struct MAX5715
|
||||
{
|
||||
const struct IODevice* device;
|
||||
struct MAX5715_DAC dac[MAX5715_NUMBER_OF_DACS];
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -79,15 +135,79 @@
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_construct
|
||||
* Description of function
|
||||
* Constructs the MAX5715 instance into argument self.
|
||||
*
|
||||
* @param self
|
||||
* @param self The MAX5715 object to initialize
|
||||
* @param device The IODevice that should be used for
|
||||
* communication with the MAX5715
|
||||
*
|
||||
* @return ErrorStatus
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715_construct(const struct IODevice* self, para2_name);
|
||||
extern ErrorStatus MAX5715_construct(struct MAX5715* self, const struct IODevice* device);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_destruct
|
||||
* Destructs the MAX5715 instance in argument self
|
||||
*
|
||||
* @param self
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void MAX5715_destruct(struct MAX5715* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_getSpiParameters
|
||||
* Returns a filled-in struct SpiParameters with the MAX5715-specific parameters
|
||||
*
|
||||
* @param parameters SpiParameters struct to fill
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715_getSpiParameters(struct SpiParameters* parameters);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_sendCommand
|
||||
* Sends a command to MAX5715 instance in argument self with the command in
|
||||
* argument command
|
||||
*
|
||||
* @param self The MAX5715 instance
|
||||
* @param command The command to be sent
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715_sendCommand(const struct MAX5715* self, uint8_t command, uint16_t data);
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715DAC_setOutput
|
||||
* Sets the output of the DAC in argument self to the value given in argument
|
||||
* value
|
||||
*
|
||||
* @param self The DAC to use
|
||||
* @param value The value to set
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715DAC_setOutput(struct MAX5715_DAC self, uint16_t value);
|
||||
|
||||
#endif /* INC_MAX5715_H_ */
|
||||
|
||||
Reference in New Issue
Block a user