Hi everyone,
I'm trying to control a MCP41100 digipot with an ATMEGA3208. I based my code on Atmel example, with the same pinout but the wiper position doesn't move at whatever value I send to it (0 to 255). Here is my simplified code for reference:
#define F_CPU 16000000
#define DIPOT_WRITE 0b00010011
#include <avr/io.h>
static void SPI0_init(void);
static uint8_t SPI0_exchangeData(uint8_t data);
static void SPI0_init(void)
{
PORTA.DIR |= PIN4_bm; /* Set MOSI pin direction to output */
PORTA.DIR |= PIN6_bm; /* Set SCK pin direction to output */
PORTA.DIR |= PIN7_bm; /* Set SS pin direction to output */
SPI0.CTRLA = SPI_ENABLE_bm /* Enable module */
| SPI_MASTER_bm /* SPI module in Master mode */
| SPI_PRESC_DIV16_gc; /* System Clock divided by 16 */
}
static uint8_t SPI0_exchangeData(uint8_t data)
{
SPI0.DATA = data;
while (!(SPI0.INTFLAGS & SPI_IF_bm)) /* waits until data is exchanged*/
{
;
}
return SPI0.DATA;
}
int main(void)
{
CCP = CCP_IOREG_gc; // No clock division (full 16Mhz)
CLKCTRL.MCLKCTRLB = 0; // No clock division (full 16Mhz)
SPI0_init();
while (1)
{
PORTA.OUT &= ~PIN7_bm; // Set SS pin value to LOW
SPI0_exchangeData(DIPOT_WRITE); // Write command for the MCP41100
SPI0_exchangeData(10); // Random value from 0 to 255
PORTA.OUT |= PIN7_bm; // Set SS pin value to HIGH
}
}
Any pointers would be much appreciated!
Thank you,
Octave


