I have additional questions relating to my last posting, "TMS320F280049C: SPI FIFO interrupt". In my SPI slave application, I want to interrupt only when the FIFO reaches haft full. I don't want the SPI slave to interrupt for any other reason. My SPI application is somewhat different in that the slave application does not store or even read data coming from the master. It only transmits out data to the master and that is controlled by the master's clock and CS. Please see my code below. Please see tiff images below. tiff images can be viewed using Windows Photo Viewer.
Problems:
1; The first 11 data are not transmitted and the last 4 data are data transmitted from the master. Please see master com output.
Sent Data:
161 178 195 212 229 246 26 43 60 77 94 111 119 136 153
Received Data:
0 0 0 0 0 0 0 0 0 0 0 77 94 111 119
2; The FIFO haft full ISR triggers 14.10uS after the CS goes high. Please see 2022-08-08 11_27_37-TEK0016.tiff image.
Obviously, I'm getting the interrupt functions wrong. Please help.
//################################################################################################## // // TITLE: 10mm_Data_Output_fifo_interrupts // //! This program uses the two SPI modules. Both the SPI FIFOs and their interrupts are used. //! SPIA is configured as a slave and transmits data to a master TIVA on the MFC control board. //! SPI B is configured as a master and receives data from the ADS2161 on the 10mm_Top-hat board. //! //! The 10mm_Top-hat board will send a DRDY (data ready) positive pulse of between 50uS and 100uS. //! The falling edge will trigger a interrupt in the master TIVA on the MFC control board. //! //! External Connections //! -GPIO24 and GPIO16 - SPISIMO GPIO24 is pin 75 and GPIO16 is pin 67 on the 120 pin edge connector. GPIO24 is set to pin 75 through S5 in the default setting. //! -GPIO31 and GPIO17 - SPISOMI GPIO31 is pin 74 and GPIO17 is pin 69 on the 120 pin edge connector. //! -GPIO22 and GPIO56 - SPICLK GPIO22 is pin 72 and GPIO56 is pin 103 on the 120 pin edge connector. //! -GPIO27 and GPIO57 - SPISTE GPIO27 is pin 81 and GPIO57 is pin 70 on the 120 pin edge connector. GPIO27 is set to pin 81 through S6 in the default setting. //! //################################################################################################# // // Included Files // #include "driverlib.h" #include "device.h" #include "board.h" #define numData 40 typedef unsigned char uint8_t; // // Globals // volatile uint16_t sData[numData]; // Send data buffer static uint16_t DataPtr = 0; static bool interruptFlag = true; //####################################################################################### // Slave output data. // See "Proposal SPI Communication Protocol for Keller Pressure Sensor.docx" on the WIKI. // Will be implemented later. // // This union is used to send floating point data over the SPI. // union { uint32_t Integer; float Float; } cpd, // CalculatedPressureData Pressure range is 0 torr to 2585.75 torr ctd, // CalculatedTemeratureData Temperature range is 15°C to 45°C sfs, // SensorFullScale For the TE 85U, the sfs is 2585.75 torr (50psi) szs; // SensorZeroScale For the TE 85U, the sfs is 0 torr uint8_t statusByte; uint32_t serialNum; uint8_t pressureMode; uint16_t pollingRate; char productNum[16]; //####################################################################################### // // Function Prototypes // __interrupt void spiaTxFIFO_ISR(void); // // Main // void main(void) { // // Initialize device clock and peripherals // Device_init(); // // Disable pin locks and enable internal pull-ups. // Device_initGPIO(); // // Board initialization // Board_init(); // // Initialize PIE and clear PIE registers. Disables CPU interrupts. // Interrupt_initModule(); // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // Interrupt_initVectorTable(); // // Interrupts that are used in this example are re-mapped to ISR functions // found within this file. // Interrupt_register(INT_SPIA_TX, &spiaTxFIFO_ISR); // // Clear SPI receive and transmit buffers // SPI_reset(SPIA_slave_BASE); // // Transmit data initialization. Because the transmit and receive data // length is 8 bits and the MSB is transmitted first, this initialization pre-shifts the data. // sData[0] = 0x0100; // 1 dec sData[1] = 0x0200; // 2 dec sData[2] = 0x0400; // 4 dec sData[3] = 0x0800; // 8 dec sData[4] = 0x1000; // 16 dec sData[5] = 0x2000; // 32 dec sData[6] = 0x4000; // 64 dec sData[7] = 0x8000; // 128 dec sData[8] = 0x1100; // 17 dec sData[9] = 0x1200; // 18 dec sData[10] = 0x1400; // 20 dec sData[11] = 0x1800; // 24 dec sData[12] = 0x2100; // 33 dec sData[13] = 0x2200; // 34 dec sData[14] = 0x2400; // 36 dec sData[15] = 0x2800; // 40 dec sData[16] = 0x4100; // 65 dec sData[17] = 0x4200; // 66 dec sData[18] = 0x4400; // 68 dec sData[19] = 0x4800; // 72 dec // // Enable Global Interrupt (INTM) and Realtime Interrupt (DBGM) // EINT; // Does the same thing that Interrupt_enableMaster(). ERTM; // enables debug events // // Preload SPI slave output buffer. // This is required because the output buffer must have something in it // so when the SPI A slave receive ISR triggers, it will have something // transmit. The resulting ISR will preload the next slave output data // for the next ISR. // // // Loop forever. // while(1) { if(GPIO_readPin(57) & interruptFlag) // GPIO_readPin(57) returns the value of GPIO57 which is the CS of the SPIA module. { // If true (high) then the SPIA has not been selected. // // Disable the SPIA interrupt for Rx events. // Interrupt_disable(INT_SPIA_TX); SPI_disableInterrupt(SPIA_BASE, SPI_INT_TXFF); SPI_disableFIFO(SPIA_slave_BASE); // disabling and enabling FIFO resets FIFO data to 0. SPI_enableFIFO(SPIA_slave_BASE); SPI_reset(SPIA_slave_BASE); // Clear SPI receive and transmit buffers interruptFlag = false; for(DataPtr = 0; DataPtr < 16; DataPtr++) // This loop preloads the output FIFO of the slave SPIA before the { // slave SPIA is selected. The SPIA FIFPO is 16 words deep. DataPtr SPI_writeDataNonBlocking(SPIA_BASE, (sData[DataPtr])); // is a global static variable and will be used in the FIFO interrupt. } // // Enable the SPIA interrupt for Rx events. // // Interrupt_enable(INT_SPIA_TX); // Enable SPIA interrupt in the PIE: Group 6 SPI_enableInterrupt(SPIA_BASE, SPI_INT_TXFF); // Enable the SPIA interrupt for Tx and Rx events. } else if(!GPIO_readPin(57) & !interruptFlag) // If GPIO_readPin(57) and interruptFlag are false, then the SPIA slave is active. { interruptFlag = true; // Set the interruptFlag = true in preparation to reload the SIPA slave FIFO for new data transfer. } } } // // SPI A slave TX FIFO ISR // This interrupt is triggered because the slave TX FIFO // status has reached the FIFO trigger level. // __interrupt void spiaTxFIFO_ISR(void) { uint16_t i; GPIO_writePin(myGPIOPin57, false); // Oscilloscope timing signal // // write data // for(i = 0; i < 8; i++) { SPI_writeDataNonBlocking(SPIA_BASE, (sData[DataPtr])); // This is preloading the output FIFO. DataPtr++; } // // Clear interrupt flag and issue ACK // SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RX_DATA_TX_EMPTY); Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP6); GPIO_writePin(myGPIOPin57, true); // Oscilloscope timing signal }
/* * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include "board.h" void Board_init() { EALLOW; PinMux_init(); GPIO_init(); SPI_init(); EDIS; } void PinMux_init() { // GPIO25 -> myGPIOPin57 Pinmux GPIO_setPinConfig(GPIO_25_GPIO25); // // SPIA -> SPIA_slave Pinmux // GPIO_setPinConfig(GPIO_16_SPIA_SIMO); GPIO_setPinConfig(GPIO_17_SPIA_SOMI); GPIO_setPinConfig(GPIO_56_SPIA_CLK); GPIO_setPinConfig(GPIO_57_SPIA_STE); } void GPIO_init(){ //myGPIOPin57 initialization GPIO_setDirectionMode(myGPIOPin57, GPIO_DIR_MODE_OUT); GPIO_setPadConfig(myGPIOPin57, GPIO_PIN_TYPE_PULLUP); GPIO_setMasterCore(myGPIOPin57, GPIO_CORE_CPU1); GPIO_setQualificationMode(myGPIOPin57, GPIO_QUAL_ASYNC); } void SPI_init() { //SPIA_slave initialization SPI_disableModule(SPIA_slave_BASE); SPI_setConfig(SPIA_slave_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA1, SPI_MODE_SLAVE, 1000000, 8); SPI_enableFIFO(SPIA_slave_BASE); SPI_setFIFOInterruptLevel(SPIA_slave_BASE, SPI_FIFO_TX8, SPI_FIFO_RX8); SPI_clearInterruptStatus(SPIA_slave_BASE, SPI_INT_TXFF); SPI_enableInterrupt(SPIA_slave_BASE, SPI_INT_TXFF); SPI_disableLoopback(SPIA_slave_BASE); SPI_setEmulationMode(SPIA_slave_BASE, SPI_EMULATION_FREE_RUN); SPI_enableModule(SPIA_slave_BASE); }
2022-08-08 11_15_42-TEK0015.tiff 2022-08-08 11_27_37-TEK0016.tiff 2022-08-08 11_32_54-TEK0017.tiff