I am using a TMS320F2812 (will refer to as DSP from here on) to communicate with an EtherCAT Slave controller that uses ET1100 chipset.
I want to establish a 8 bit SPI communication where DSP is Master and Et1100 is slave.
My problems include
1. the SPI ENABLE LINE DOES NOT WORK AS INTENDED. I want the SPI ENABLE line to become active (low) at start of communication and then go inactive (high) AFTER 8 BITS are communicated. This also leads me to the question whether after I load the TXBUF should I wait for x micro/milli seconds before loading the next TXBUF? Does this also cause the ENABLE line to not work as intended?
The following functions are to read and write to/from the et1100.
void ESC_read(uint16_t address, void *buf, uint16_t len, void *tALevent) { uint16_t count = 0; unsigned int *ptr; uint16_t adr = 0; uint16_t i = 0; //adr = address; adr = (address<<3)+ESC_CMD_READ; ptr = tALevent; // Chip select low EALLOW; GpioDataRegs.GPFDAT.bit.GPIOF3 = 0; // Transmit Enable (SYNC) //SpiaRegs.SPICTL.bit.TALK = 1; EDIS; SpiaRegs.SPITXBUF = adr; while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); __byte(ptr,0) = (SpiaRegs.SPIRXBUF&0x00FF); SpiaRegs.SPITXBUF = send_8bit(adr); while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); __byte(ptr,1) = (SpiaRegs.SPIRXBUF&0x00FF); count = len; ptr = buf; while ((count--) > 1) { i=0; SpiaRegs.SPITXBUF = ESC_NEXT; while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); __byte(ptr,i) = (SpiaRegs.SPIRXBUF&0x00FF); i++; } SpiaRegs.SPITXBUF = ESC_TERM; while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); // Chip select high EALLOW; // SpiaRegs.SPICTL.bit.TALK = 0; GpioDataRegs.GPFDAT.bit.GPIOF3 = 1; // Transmit DISable (SYNC) EDIS; __byte(ptr,i) = (SpiaRegs.SPIRXBUF&0xFF); }
void ESC_write(uint16_t address, void *buf, uint16_t len, void *tALevent) { uint16_t count; uint16_t dummy; unsigned int *ptr; uint16_t adr; adr = ((address<<3)+ESC_CMD_WRITE); ptr = tALevent; // Chip select low EALLOW; GpioDataRegs.GPFDAT.bit.GPIOF3 = 0; // Transmit Enable (SYNC) // SpiaRegs.SPICTL.bit.TALK = 1; EDIS; SpiaRegs.SPITXBUF = adr; while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); __byte(ptr,0) = (SpiaRegs.SPIRXBUF&0x00FF); SpiaRegs.SPITXBUF = send_8bit(adr); while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); __byte(ptr,1) = (SpiaRegs.SPIRXBUF&0x00FF); count = len; ptr = buf; while ((count--) > 0) { uint16_t i=0; SpiaRegs.SPITXBUF = send_8bit(__byte(ptr,i)); i++; while ( ! SpiaRegs.SPISTS.bit.INT_FLAG ); dummy = SpiaRegs.SPIRXBUF; } // Chip select high EALLOW; // SpiaRegs.SPICTL.bit.TALK = 0; GpioDataRegs.GPFDAT.bit.GPIOF3 = 1; // Transmit DISable (SYNC) EDIS; }
Summarizing - My primary concern is the SPI does not work as intended.
Also attaching the SPI initialization.
static void spi_init(void) { EALLOW; GpioMuxRegs.GPFMUX.all=0x000F; // Select GPIOs to be SPI pins // Port F MUX - x000 0000 0000 1111 EDIS; DINT; // Initialize SPI FIFO registers SpiaRegs.SPIFFTX.all=0xA040; SpiaRegs.SPIFFRX.all=0x2040; SpiaRegs.SPIFFCT.all=0x0; SpiaRegs.SPICCR.all =0x0047; // Reset on, (clk pol=1 : Falling edge), 8-bit char bits SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase, // enable talk, and SPI int disabled. SpiaRegs.SPIBRR =0x007F; // 150 MHz/4/(127+1)= 292.3 KHz SpiaRegs.SPICCR.all =0x00C7; // Relinquish SPI from Reset SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission }