Tool/software: Code Composer Studio
Hi,
I try to communicate with the TDC7200 and the MSP430 5529lp over SPI.
The Write operations are successfully but when i want to read the same Register which I wrote before whithout any Interrupt.
I see on the Scope only the read adress +command.
Now my Question is it possible to read without interrupt? and where is my mistake?
I am a newbie^^ and I hope anyone can help me with this Problem
The Code:
#include <msp430.h> #include <stdint.h> /** * main.c */ uint8_t read_val; unsigned long rcv; unsigned char data; void SPI_init(void); void SPI_write_config1(uint8_t,uint8_t); void SPI_write_config2(uint8_t,uint8_t); void SPI_write_config3(uint8_t,uint8_t); uint8_t SPI_write_read_TIME(uint8_t); int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer SPI_init(); SPI_write_config1(0x40,0x02); //write register adress 00h with commands SPI_write_config2(0x41,0x40); SPI_write_config3(0x42,0x00); read_val=SPI_write_read_TIME(0x00); // example: read register adress 00h } void SPI_write_config1(uint8_t adress,uint8_t value) { P2OUT &= (~BIT2); // Select Device while(!(UCB0IFG & UCTXIFG)); // wait for TXBUF UCB0TXBUF = adress; // send adress to register 00h while(!(UCB0IFG & UCTXIFG)); // wait for TXBUF UCB0TXBUF = value; // write a command to register 00h while (UCB0STAT & UCBUSY); // Wait for TX complete P2OUT |= (BIT2); // Unselect Device } void SPI_write_config2(uint8_t adress,uint8_t value) { P2OUT &= (~BIT2); // Select Device while(!(UCB0IFG & UCTXIFG)); // wait for TXBUF UCB0TXBUF = adress; // send adress to register 01h while(!(UCB0IFG & UCTXIFG)); // wait for TXBUF UCB0TXBUF = value; // write a command to register 01h while (UCB0STAT & UCBUSY); // Wait for TX complete P2OUT |= (BIT2); // Unselect Device } void SPI_write_config3(uint8_t adress,uint8_t value) { P2OUT &= (~BIT2); // Select Device while(!(UCB0IFG & UCTXIFG)); // wait for TXBUF UCB0TXBUF = adress; // send adress to register 01h while(!(UCB0IFG & UCTXIFG)); // wait for TXBUF UCB0TXBUF = value; // write a command to register 01h while (UCB0STAT & UCBUSY); // Wait for TX complete P2OUT |= (BIT2); // Unselect Device } void SPI_init(void) { // SPI Pins Auswählen// P3SEL = BIT0 + BIT1 + BIT2; P2DIR |= BIT2; // PIN2.2 set as Chipselect P2OUT |= BIT2; // PIN2.2 set the chipselect Pin high // Konfiguration des SPI-Registers// UCB0CTL1 |= UCSWRST; UCB0CTL1 |= UCSSEL_2; UCB0CTL0 = UCMST+UCMSB+UCCKPL+UCSYNC; // SPI Konfiguration (MasterMode;SynchroneMode;Clock_polarity;MSBfirstMode) UCB0BR0 = 0x02; // Prescaler UCB0BR1 = 0; UCA0MCTL = 0; // No Modulation UCB0CTL1 &= ~UCSWRST; // disable software reset } uint8_t SPI_write_read_TIME(uint8_t adress) { P2OUT &= (~BIT2); // Select Device while(!(UCB0IFG & UCTXIFG)); // Wait for TXBUF ready UCB0TXBUF = adress; // send ADRESSE + read command to the register while (!(UCB0IFG&UCTXIFG)); // Wait for TXBUF ready UCB0TXBUF = 0; // Dummy write to read data while(!(UCB0IFG&UCRXIFG)); // Wait for RXBUF ready rcv = UCB0RXBUF; P2OUT |= (BIT2); // Unselect Device return (rcv); }