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:
@@ -25,7 +25,11 @@
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include "MAX5715.h"
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -53,3 +57,83 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus MAX5715_construct(struct MAX5715* self, const struct IODevice* device)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
int loopCounter;
|
||||
if (self != NULL)
|
||||
{
|
||||
self->device = device;
|
||||
|
||||
for (loopCounter = 0; loopCounter < MAX5715_NUMBER_OF_DACS; loopCounter++)
|
||||
{
|
||||
self->dac[loopCounter].id = loopCounter;
|
||||
self->dac[loopCounter].value = 0x0000;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void MAX5715_destruct(struct MAX5715* self)
|
||||
{
|
||||
self->device = NULL;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus MAX5715_getSpiParameters(struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if ((configCPU_CLOCK_HZ / 2) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 4) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 8) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CPU clock is too high. The pre-scaler has a max of 256. A clock higher than 25,6 MHz
|
||||
// results in a SPI CLK higher than 100 kHz, which is the max of the display
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
// SPI pre-scaler was no problem - assign the remaining parameters
|
||||
parameters->SPI_CPHA = MAX5715_SPI_CPHA;
|
||||
parameters->SPI_CPOL = MAX5715_SPI_CPOL;
|
||||
parameters->SPI_CRCPolynomial = MAX5715_SPI_CRCPolynomial;
|
||||
parameters->SPI_DataSize = MAX5715_SPI_DataSize;
|
||||
parameters->SPI_Direction = MAX5715_SPI_Direction;
|
||||
parameters->SPI_FirstBit = MAX5715_SPI_FirstBit;
|
||||
parameters->SPI_Mode = MAX5715_SPI_Mode;
|
||||
parameters->SPI_NSS = MAX5715_SPI_NSS;
|
||||
parameters->SPI_NSS_internal = MAX5715_SPI_NSS_INTERNAL;
|
||||
parameters->rxQueueSize = MAX5715_SPI_RX_QUEUE;
|
||||
parameters->txQueueSize = MAX5715_SPI_TX_QUEUE;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus MAX5715_sendCommand(const struct MAX5715* self, uint8_t command, uint16_t data)
|
||||
{
|
||||
char buffer[3] = {(char)command, (char)(data >> 4), (char)((data << 4) & 0x00F0)};
|
||||
|
||||
return IODevice_write(self->device, buffer, 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user