Hi,
I'm trying to communicate the TMS320F28377xS with the DDS AD9833. The MCU works as a master and the DDS as a slave. I only need to send data, therefore I'm using a 3-wire SPI.
When I look at the Oscilloscope, seems to be fine, I can see the correct data been transfered on the falling edge. (Figure bellow. Data 0x5893 (CH2) being transfered on the falling edge, CH1 = SCLK, CH3 = EN).
However, when I transmit this to the DDS I don't get the expected result. So I tried to analyze the waveforms with the Picoscope. Here is the result:
It seems like I'm always missing the last bit (LSB).
Does anyone have any idea how can I fix this?
Here is my actual code:
/** * main.c */ #include "Peripheral_Setup.h" #include "math.h" #include <stdint.h> Uint32 count = 0; Uint16 data_vector[] = {0x2100, 0x4010, 0x5893, 0xC000, 0x2000}; //Sine - I need 5 writes to get the sine on DDS output Uint16 rdata; Uint16* ptr = data_vector; Uint16 flag = 0; void spi_xmit(Uint16 a); void spi_fifo_init(void); void spi_init(void); int main(void) { //Initializations InitSysCtrl(); // Initialize System Control: InitGpio(); //InitSpiaGpio(); EALLOW; CpuSysRegs.PCLKCR0.bit.CPUTIMER0 = 1; EDIS; DINT; // Disable CPU interrupts InitPieCtrl(); // Initialize the PIE control registers to their default state IER = 0x0000; // Disable CPU interrupts IFR = 0x0000; // Clear all CPU interrupt flags: InitPieVectTable(); // Initialize the PIE vector table //Functions Setup_GPIO(); Setup_ePWM(); Setup_ADC(); spi_init(); //Initialize the SPI spi_fifo_init(); //Initialize the SPI FIFO EALLOW; PieVectTable.TIMER0_INT = &isr_cpu_timer0; //PieVectTable.ADCA1_INT = &isr_adc; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //Timer 0 //PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //ADC EDIS; IER |= M_INT1; InitCpuTimers(); ConfigCpuTimer(&CpuTimer0, 200, 0.5); //Not being used CpuTimer0Regs.TCR.all = 0x4001; EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM //Infinit Loop while(1){ if(flag !=1){ spi_xmit(ptr[count]); while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { } rdata = SpiaRegs.SPIRXBUF; count = count+1; } if(count>4){count = 0; flag = 1;} //After the 5 writing, no data is transfered anymore } return 0; } __interrupt void isr_cpu_timer0(void){ //Not being used PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; } void spi_xmit(Uint16 a) { SpiaRegs.SPITXBUF = a; } void spi_fifo_init() { SpiaRegs.SPIFFTX.all = 0xE040; SpiaRegs.SPIFFRX.all = 0x2044; SpiaRegs.SPIFFCT.all = 0x0; }
My SPI is configured as follow:
void spi_init(void){ EALLOW; SpiaRegs.SPICCR.all =0x00DF; SpiaRegs.SPICTL.all =0x001E; SpiaRegs.SPIBRR.all =49; //Baud rate = 1MHz SpiaRegs.SPIPRI.bit.FREE = 1; EDIS; }
Thanks in advance!