Other Parts Discussed in Thread: ADS127L01
Tool/software: Code Composer Studio
Hello,
I'm a little new around here. I looked at old posts, but I couldn't find an answer for my issue.
I'm using EK-TM4C1294XL via Code Composer Studio Version: 8.3.1.00004 and spiloopback. Also I have ADS127L01EVM.
With these parts, I'm making ADC and I want to read with EK-TM4C1294XL (SPI) than I want to send It to the CAN line.
spiloopback.h is working on the EK-TM4C1294XL but I can not read any data from ADS127L01EVM.
I build like the jumper wire connections are needed for the external SPI loopback example. | PD3->PQ0, PD2->PQ1, PD0->PQ2, PD1->PQ3 and the spiloopback works.
Now,
TM4C PQ1 to GND
ADS SCLK ->TM4C PQ0 - SLAVE
ADS DIN -> TM4C PQ2 - SLAVE
ADS DOUT -> TM4C PQ3 - SLAVE
ADS input frequency is 16MHz and output (DOUT) frequency is about 130kHz. It works and i add my oscilloscope-screenshots
so I made some additions to the program.
slaveSpiParams.transferMode = SPI_MODE_BLOCKING; //added
slaveSpiParams.bitRate = 130000; //added
This is my Console on Code Composer
SPI initialized
SPI initialized
Master:
Done
Q: Why can't I get data?
Q: Is there a simpler example you can recommend?
Q: This program is running once. if i add a "while loop" , can it work continuously?
Thank You
/* ======== spiloopback.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
/* Example/Board Header files */
#include "Board.h"
#define SPI_MSG_LENGTH 30
#define TASKSTACKSIZE 768
Task_Struct task0Struct, task1Struct;
Char task0Stack[TASKSTACKSIZE], task1Stack[TASKSTACKSIZE];
unsigned char masterRxBuffer[SPI_MSG_LENGTH];
unsigned char masterTxBuffer[SPI_MSG_LENGTH] = "Hello, this is master SPI1234";
unsigned char slaveRxBuffer[SPI_MSG_LENGTH];
unsigned char slaveTxBuffer[SPI_MSG_LENGTH] = "Hello, this is slave SPI1234";
/* * ======== slaveTaskFxn ========
* Task function for slave task.
*
* This task runs on a higher priority, since slave
* has to be ready for master. Slave SPI sends a
* message to master and also receives message from
* master. Task for this function is created
* statically. See the project's .cfg file.
*/
Void slaveTaskFxn (UArg arg0, UArg arg1)
{
SPI_Handle slaveSpi;
SPI_Params slaveSpiParams;
SPI_Transaction slaveTransaction;
bool transferOK;
/* Initialize SPI handle with slave mode */
SPI_Params_init(&slaveSpiParams);
slaveSpiParams.transferMode = SPI_MODE_BLOCKING; //eklendi
slaveSpiParams.mode = SPI_SLAVE;
slaveSpiParams.bitRate = 130000;
slaveSpi = SPI_open(Board_SPI1, &slaveSpiParams);
if (slaveSpi == NULL) {
System_abort("Error initializing SPI\n");
}
else {
System_printf("SPI initialized\n");
}
/* Initialize slave SPI transaction structure */
slaveTransaction.count = SPI_MSG_LENGTH;
slaveTransaction.txBuf = (Ptr)slaveTxBuffer;
slaveTransaction.rxBuf = (Ptr)slaveRxBuffer;
/* Initiate SPI transfer */
transferOK = SPI_transfer(slaveSpi, &slaveTransaction);
if(transferOK) {
/* Print contents of slave receive buffer */
System_printf("Slave: %s\n", slaveRxBuffer);
}
else {
System_printf("Unsuccessful slave SPI transfer");
}
/* Deinitialize SPI */
SPI_close(slaveSpi);
}
/*
* ======== masterTaskFxn ========
* Task function for master task.
*
* This task runs at a lower priority after the slave
* task to ensure it is ready for a transaction.
* Master SPI sends a message to slave and also
* receives message from slave. Task for this function
* is created statically. See the project's .cfg
* file.
*/
Void masterTaskFxn (UArg arg0, UArg arg1)
{
SPI_Handle masterSpi;
SPI_Transaction masterTransaction;
SPI_Params masterSpiParams;
bool transferOK;
masterSpiParams.bitRate = 130000;
/* Initialize SPI handle as default master */
masterSpi = SPI_open(Board_SPI0, NULL);
if (masterSpi == NULL) {
System_abort("Error initializing SPI\n");
}
else {
System_printf("SPI initialized\n");
}
/* Initialize master SPI transaction structure */
masterTransaction.count = SPI_MSG_LENGTH;
masterTransaction.txBuf = (Ptr)masterTxBuffer;
masterTransaction.rxBuf = (Ptr)masterRxBuffer;
/* Initiate SPI transfer */
transferOK = SPI_transfer(masterSpi, &masterTransaction);
if(transferOK) {
/* Print contents of master receive buffer */
System_printf("Master: %s\n", masterRxBuffer);
}
else {
System_printf("Unsuccessful master SPI transfer");
}
/* Deinitialize SPI */
SPI_close(masterSpi);
System_printf("Done\n");
System_flush();
}
/*
* ======== main ========
*/
int main(void)
{
/* Construct BIOS objects */
Task_Params taskParams;
/* Call board init functions. */
Board_initGeneral();
Board_initGPIO();
Board_initSPI();
/* Construct master/slave Task threads */
Task_Params_init(&taskParams);
taskParams.priority = 1;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)masterTaskFxn, &taskParams, NULL);
taskParams.stack = &task1Stack;
taskParams.priority = 2;
Task_construct(&task1Struct, (Task_FuncPtr)slaveTaskFxn, &taskParams, NULL);
/* Turn on user LED */
GPIO_write(Board_LED0, Board_LED_ON);
System_printf("Starting the SPI loop-back example\nSystem provider is set to"
" SysMin. Halt the target to view any SysMin contents in ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
System_printf("This example requires external wires to be connected to the "
"header pins. Please see the Getting Started Guide for "
"details.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}





