Hi all.....
Please help in below matter regarding usage of SPI interface.
I was writing code for DAC7564 interface with MSP using 3 wire SPI. Is there any need to set the CCKPL and CCKPH bits here in case of DAC7564. When should one decide to set the clock polarity bits based on the slave timing diagram.
I am using XT2 crystal 16Mhz and MCLK = 16Mhz followed by SMCLK at 8MHZ .
As per hardware is concerned i am uisng internal reference. I am sometimes able to power down the internal reference using the code below and update channel A sometimes by changing just the bytes to be sent it dos not function properly. Also i observed the UCOE flag sets after I transmit the first byte alongwith TXIFG andRXIFg flags. As per in user guide as soon as we write in UCB2TXBUF the UTXIFG flag clears automatically but it does not happen so when i debugged the code step by step.
Also when i measured the UCLK it shows 1.56Mhz. What is the role of UCB2BR0 register here.
void SPI_INIT(void)
{
_P9SEL.bit.P9SEL_0 = 0; // configure as chip select pin
_P9DIR.bit.P9DIR_0 = 1; // configure as output pin
_P9SEL.bit.P9SEL_3 = 1;
_P9SEL.bit.P9SEL_1 = 1;
UCB2CTL0 |= (UCMSB + UCMST + UCSYNC + UCCKPH); // 3-pin, 8-bit SPI mstr, MSB 1st,CPHA =1,CPOL=0
UCB2CTL1 |= UCSSEL_2; // SPI clk source----> SMCLK 8Mhz
UCB2BR0 = 0x02;
UCB2BR1 = 0;
UCB2CTL1 &= ~UCSWRST; //**Initialize USCI state machine**
// IE2 |= UCB0TXIE; //Enable SPI transmit interrupt
}
Considering that I have initialized the SPI module as per the sample code. My transmit routine is as follows:-
void SPI_TRANSMIT(unsigned char byte)
{
while (!(UCB2IFG & UCTXIFG));
UCB2TXBUF = byte;
}
i am calling the above function as shown below in main.c
SPI_START(); //pull sync line low (simple port pin)
SPI_TRANSMIT(0x01);
SPI_TRANSMIT(0x12);
SPI_TRANSMIT(0x00);
SPI_STOP(); //pull sync line high
regards,
harshit