Other Parts Discussed in Thread: HALCOGEN
Hello, Ti community. I'm currently working on the Hercules Hardware Development Kit (TMS570LC4357-EP)
I am unable to read data from an external hardware (data key) using the SPI protocol, but I tested the mibSPI example code (both loopback and DMA) provided in the HALCogen software and saw the data transfer between internal registers, which works perfectly.
I'm connecting external hardware (data key) using the SPI pin combinations listed below:
J-10 SPI2 expansion connector-
Pin 64 of the CLK
CS0- pin 63
Pin 59 of the SOMI
Pin 61 of SIMO
I have tried an example SPI code, which is attached below, and the data transport works perfectly internally. However, I require code that receives data from external hardware (data key) using the previously specified SPI2 pin arrangement, in which my HDK acts as master and the external hardware (data key) acts as slave device.
/** @file HL_sys_main.c * @brief Application main file * @date 11-Dec-2018 * @version 04.07.01 * * This file contains an empty main function, * which can be used for the application. */ /* * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com * * * 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. * */ /* USER CODE BEGIN (0) */ /* USER CODE END */ /* Include Files */ #include "HL_sys_common.h" /* USER CODE BEGIN (1) */ #include "HL_sys_core.h" #include "HL_sys_dma.h" #include "HL_spi.h" //#include "HL_sci.h" //#include <ra_dbg_level.h> //#include <ra_stdio.h> /* USER CODE END */ /** @fn void main(void) * @brief Application main function * @note This function is empty by default. * * This function is called after startup. * The user can use this function to implement the application. */ /* USER CODE BEGIN (2) */ #define WITH_DMA 0 #define LOOP_BACK 1 #define D_SIZE 128 #define SPI_MASTER spiREG3 #define MASTER_SPI_TX_ADDR ((uint32_t)(&(spiREG3->DAT1)) + 2) #define MASTER_SPI_RX_ADDR ((uint32_t)(&(spiREG3->BUF)) + 2) uint16 tx_data[D_SIZE] = {0}; uint16 rx_data[D_SIZE] = {0}; unsigned int MASTER_SPI_DMA_FTCFlag = 0; unsigned int MASTER_SPI_DMA_HBCFlag = 0; unsigned int MASTER_SPI_DMA_BTCFlag = 0; g_dmaCTRL g_dmaCTRLPKT_RX, g_dmaCTRLPKT_TX; static void loadDataPattern (uint32 psize, uint16* pptr); #if (WITH_DMA) static void dmaConfigCtrlTxPacket (uint32 sadd, uint32 dadd, uint16 ElmntCnt, uint16 FrameCnt); static void dmaConfigCtrlRxPacket (uint32 sadd, uint32 dadd, uint16 ElmntCnt, uint16 FrameCnt); #endif /* USER CODE END */ int main(void) { /* USER CODE BEGIN (3) */ _enable_IRQ_interrupt_(); loadDataPattern(D_SIZE,&tx_data[0]); spiInit(); #if (LOOP_BACK) spiEnableLoopback(SPI_MASTER, Analog_Lbk); #endif #if (WITH_DMA) /* - setting the dma channel to trigger on h/w request */ dmaSetChEnable(DMA_CH0, DMA_HW); dmaSetChEnable(DMA_CH1, DMA_HW); dmaReqAssign(DMA_CH0, DMA_REQ14); //SPI3 RX dmaReqAssign(DMA_CH1, DMA_REQ15); //SPI3 TX dmaConfigCtrlRxPacket(MASTER_SPI_RX_ADDR, (uint32)rx_data, 1, D_SIZE); //TBC dmaSetCtrlPacket(DMA_CH0, g_dmaCTRLPKT_RX); /* - setting dma control packets */ dmaConfigCtrlTxPacket((uint32)tx_data, MASTER_SPI_TX_ADDR, 1, D_SIZE); //TBC dmaSetCtrlPacket(DMA_CH1, g_dmaCTRLPKT_TX); dmaEnable(); SPI_MASTER->INT0 |= (0x1 << 16); //SPI_DMAREQ; Enable DMA REQ only after setting the SPIEN bit to 1. #else spiDAT1_t dataconfig3_t; dataconfig3_t.CS_HOLD = FALSE; dataconfig3_t.WDEL = TRUE; dataconfig3_t.DFSEL = SPI_FMT_0; dataconfig3_t.CSNR = 0xFE; spiTransmitAndReceiveData(SPI_MASTER, &dataconfig3_t, D_SIZE, tx_data,rx_data); #endif while(1); /* USER CODE END */ return 0; } /* USER CODE BEGIN (4) */ void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel) { if (inttype == FTC) { MASTER_SPI_DMA_FTCFlag = 1; } else if (inttype == HBC) { MASTER_SPI_DMA_HBCFlag = 1; } else if (inttype == BTC) { MASTER_SPI_DMA_BTCFlag = 1; } } static void loadDataPattern(uint32 psize, uint16* pptr) { int i; for(i=0;i<psize;i++) { pptr[i] = i; } } #if (WITH_DMA) static void dmaConfigCtrlTxPacket (uint32 sadd, uint32 dadd, uint16 ElmntCnt, uint16 FrameCnt) { /* - configuring dma control packets */ g_dmaCTRLPKT_TX.SADD = sadd; g_dmaCTRLPKT_TX.DADD = dadd; g_dmaCTRLPKT_TX.CHCTRL = 0; g_dmaCTRLPKT_TX.FRCNT = FrameCnt; g_dmaCTRLPKT_TX.ELCNT = ElmntCnt; g_dmaCTRLPKT_TX.ELDOFFSET = 0; g_dmaCTRLPKT_TX.ELSOFFSET = 0; g_dmaCTRLPKT_TX.FRDOFFSET = 0; g_dmaCTRLPKT_TX.FRSOFFSET = 0; g_dmaCTRLPKT_TX.PORTASGN = PORTA_READ_PORTB_WRITE; g_dmaCTRLPKT_TX.RDSIZE = ACCESS_16_BIT; g_dmaCTRLPKT_TX.WRSIZE = ACCESS_16_BIT; g_dmaCTRLPKT_TX.TTYPE = FRAME_TRANSFER; g_dmaCTRLPKT_TX.ADDMODERD = ADDR_INC1; g_dmaCTRLPKT_TX.ADDMODEWR = ADDR_FIXED; g_dmaCTRLPKT_TX.AUTOINIT = AUTOINIT_OFF; } static void dmaConfigCtrlRxPacket (uint32 sadd, uint32 dadd, uint16 ElmntCnt, uint16 FrameCnt) { /* - configuring dma control packets */ g_dmaCTRLPKT_RX.SADD = sadd; g_dmaCTRLPKT_RX.DADD = dadd; g_dmaCTRLPKT_RX.CHCTRL = 0; g_dmaCTRLPKT_RX.FRCNT = FrameCnt; g_dmaCTRLPKT_RX.ELCNT = ElmntCnt; g_dmaCTRLPKT_RX.ELDOFFSET = 0; g_dmaCTRLPKT_RX.ELSOFFSET = 0; g_dmaCTRLPKT_RX.FRDOFFSET = 0; g_dmaCTRLPKT_RX.FRSOFFSET = 0; g_dmaCTRLPKT_RX.PORTASGN = PORTB_READ_PORTA_WRITE; g_dmaCTRLPKT_RX.RDSIZE = ACCESS_16_BIT; g_dmaCTRLPKT_RX.WRSIZE = ACCESS_16_BIT; g_dmaCTRLPKT_RX.TTYPE = FRAME_TRANSFER; g_dmaCTRLPKT_RX.ADDMODERD = ADDR_FIXED; g_dmaCTRLPKT_RX.ADDMODEWR = ADDR_INC1; g_dmaCTRLPKT_RX.AUTOINIT = AUTOINIT_OFF; } #endif /* USER CODE END */
1) Please review the preceding reference and submit the code for data exchange between the HDK board and external hardware (data key).
2) How and where do I adjust the SPI clock frequency?
3)When I explored the clock, I was able to extract a 50 hz clock frequency when I probed the SPI clock pin, but I also saw that the clock frequencies on the CS0, SOMI, and SIMO pins were the same.