Jump to content
Sign in to follow this  
aalsubhi

MSP430FR5989: SPI interfacing with ISL23428 digipot

Recommended Posts

Hello there,

I'm trying to program the digipot using spi communication to set the ISL23428 digipots to thier maximum values. I used the multimeter to inspect the output voltage for each digipots and the result is zero for both. I'm not sure if the issue is in my code or with the digipots.  Thanks in advance for your help.

 

#include <msp430fr5989.h>
#include <stdint.h>

#define delay(x) __delay_cycles(x * 8000UL)

void digitalPotWrite();
uint8_t SPI_transfer(uint8_t _data);
uint8_t spi_send(const uint8_t _data);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5;

// setup UCB1
 UCB1CTLW0 = UCSWRST | UCSSEL_2; // UCSWRST= Put USCI in reset mode, UCSSEL_2 = source USCI clock from SMCLK
 UCB1CTLW0 |= UCCKPH | UCMSB | UCMST | UCSYNC; //UCCKPH = SPI MODE 0(CPOL=0 CPHA=0) , UCMSB= MSB,   UCMST= master mode

 P3SEL0 |= BIT1;  // P3.1-> UCB1SIMO
 P3SEL1 &= ~ BIT1;
 P3SEL0 |= BIT2 ; //P3.2-> UCB1SOMI
 P3SEL1 &= ~ BIT2 ;
 P3SEL0 |= BIT0 ; //P3.0-> USCB1CLK
 P3SEL1 &= ~ BIT0 ;
 P1OUT |= BIT0;
 P1DIR |= BIT0; // set cs P1.0 as output
 // UCB1 set initial speed
 UCB1BR0 |= 0x02;
 UCB1BR1 = 0;
 UCB1CTLW0 &= ~UCSWRST; // release UCB1 for operation
 delay(10);
 digitalPotWrite();

 UCB1CTLW0 = UCSWRST; //spi disable
 for(;;)
 {

 }
 }

 void digitalPotWrite() {
   // take the CS pin low to select the chip:
   P1OUT &= ~BIT0;
    delay(10);
   // send writing instruction to WR0
   SPI_transfer(0b11000000); // 110 is writing instruction followed by WR0 address(00000)
    delay(10);
   SPI_transfer(0b11111111); // set WR0 to max value
    delay(10);
   // send writing instruction to WR1
   SPI_transfer(0b11000001); // 110 is writing instruction followed by WR1 address(00001)
    delay(10);
   SPI_transfer(0b11111111); // set WR1 to max value
    delay(10);
   // take the CS pin high to de-select the chip:
   P1OUT |= BIT0;
 }

 uint8_t SPI_transfer(uint8_t _data) {
     return spi_send(_data);
 }

 uint8_t spi_send(const uint8_t _data)
 {
 	/* Wait for previous tx to complete. */
 	while (!(UCB1IFG & UCTXIFG)) // UCB1 flage
 		;

 	/* Setting TXBUF clears the TXIFG flag. */
 	UCB1TXBUF = _data; // transfer buffer for UCB1

 	/* Wait for a rx character? */
 	while (!(UCB1IFG & UCRXIFG)) // UCB1 flage
 		;

 	/* Reading clears RXIFG flag. */
 	return UCB1RXBUF; //reciveing buffer for UCB1
 }

Share this post


Link to post
Share on other sites

cannot help you with your code. but happy to offer you an approach.

as written, your code has poor reusability -> meaning you or others will have a hard time re-use the code in another project, with all those hard coded pins / ports.

1) read the datasheet thoroughly and understand what's needed to communicate with the device for your application and how the communications work. for example, do you need all CS/SCK/SDI/SDO or just CS/SCK/SDI? ... Form logic pins for those connections.

 

2) write a basic set of routines that communicate with the device. the datasheet says that it is always one command / instruction byte + data bytes. if you don't mind a little bit of inefficiency, a isl23428_write(cmd, data) + is23428_read(cmd, addr) would work, using logic pins in 1) above

 

3) with that, you can then write another set of routines writing specific data to dcp channels, or the control register, using routines developed in 2).

 

4) from there, you can develop your applications.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×