This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
你好:
I am doing a wifi spi program now.
Application process: start a socket threads to establish a TCP server, enabling spi as slave mode, communicating with another module (spi master mode).After the tcpserver receives data, the data is send to a ram space (tx_buf) what is used to spi sending.Then i enable the spi - dma transmission and down a gpio pin (when master spi module detects the gpio pin down ,it starts reading data from the spi). when cc3200 slave spi dma transfer is stop , raising gpio pin (when master spi module detects the gpio pin up it stops the spi reading data). Cc3200 slave spi continuous detectes the main data from the spi master, if there have data.When recving data(rx_buf) ,the data will send to wifi by TCP server.
Now the tcp server sending data and rcving data are ok.But spi is not.I want to do it like this:
When should i rase the INTR_O.How can i know the last data has been sended to MISO gpio.
Can you send a spi-dma demo as spi slave for sending and rcving.
Thanks.
Hi Weilsng Li,
Did you take a look at the cc3200-sdk\example\spi_demo available in the SDK? This uses the SPI-CS pin to communicate with the SPI master. However, this doesnt use the DMA and does CPU polling based transfers.
Best regards,
Naveen
Hi Naveen,
I have take a look at the cc3200-sdk\example\spi_demo .I have used in my applitation,but i find the interrupt can't response immediately when the speed up to 3Mhz , and there will be data missing.So i want to use dma to transfer .
Can you teach me how to use dma in spi transfer as slave spi sending and reading.
Hi Weilsng Li,
Here is another thread regarding this : http://e2e.ti.com/support/wireless_connectivity/f/968/t/353790.aspx
You will find the code snippets for SPI slave with DMA configration. Please try to follow them.
Thanks and REgards,
Praveen
Hi Weilsng Li,
I am closing the thread, if issue still exist please open a new thread and add a link to this one for reference.
Best regards,
Naveen
Hi Praveen,
I have looked at this.I used cc3200 as slave spi mode.Now i wait for data to recive ,but i do not know how much data there will be sended by the master spi.So what should i set the word num,useing spi api.Such as
void SPIWordCountSet | ( | unsigned long | ulBase, |
unsigned long | ulWordCount | ||
) |
SetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,10,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
&g_ucRxBuff,UDMA_DST_INC_8);
Hi Weilsng,
You need to set a word count of 0 to put the SPI into continuous transfer mode.
Thanks and Regards,
Praveen
Hi Praveen,
I use the follow function send and recive data from spi.My spi is working with slave mode.
SetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,num,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
&g_ucRxBuff,UDMA_DST_INC_8);
SetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,num,
UDMA_SIZE_8,UDMA_ARB_1,
&g_ucTxBuff,UDMA_SRC_INC_8,(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);
I'm not sure how much data will recive . I want to know what the "num" should be set and when should i read data from g_ucRxBuff. Or are there other ways to read data from the master spi.
Hi Weilsng,
You will have to handle it in the software. You can implement a software level protocol, where the master sends a fixed size header with packet size information followed by the variable size actual data. Slave can choose to read the header using CPU or DMA, then set the DMA for the actual data.
Thanks and Regards,
Praveen
Hi Praveen,
Thanks for your reply.
I know it.
There is a other problem.I use this function (SetupTransfer) send data to the master spi . But the first data that the master spi recives is not the data that the slave spi sends.It is the last data that the slave spi transfers last time.
SetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,100,
UDMA_SIZE_8,UDMA_ARB_1,
&g_ucRxBuff,UDMA_SRC_INC_8,(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);
If i transfer 100 datas,after the master recive 100 datas,there will be a interrupt happen.I read the state of interrupt and report it .It displays 0x00.I want to know what is the interrupt.
ulStatus = MAP_SPIIntStatus(GSPI_BASE,true);
Report("#0x%x#",ulStatus);
MAP_SPIIntClear(GSPI_BASE,SPI_INT_DMARX|SPI_INT_DMATX);
if((ulStatus&SPI_INT_DMATX)||(ulStatus&SPI_INT_DMARX))
{
Report("spi-dma-tx-rx-wr");
/*SetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,100,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
&g_ucRxBuff,UDMA_DST_INC_8);
SetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,100,
UDMA_SIZE_8,UDMA_ARB_1,
&g_ucTxBuff,UDMA_DST_INC_NONE,(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);*/
}
Hi Weilsng,
"But the first data that the master spi recives is not the data that the slave spi sends.It is the last data that the slave spi transfers last time."
This issue will occur if the slave TX FIFO is not server on time. Where do you call SetupTransfer() ? You need to make sure that the DMA is ready to server the data as soon as it gets the request.
Will get back to you on the interrupt status issue.
Thanks and Regards,
Praveen
Hi Praveen,
Now i am working a firmware that is used for wifi to spi .I creat a tcp socket used to send and recive data through wirless.Then sending or reciving data through spi.
My cc3200 work with slave spi mode and the spi FIFO is not used.I transfer data (SetupTransfer()),when the tcp socket recive data.Then i set the INTR low to tell the master to read data from the slave spi.If there are no data ,i
SetupTransfer() to wait to recive data from the master spi.Like the below :
SetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
&spi_recive_data,UDMA_DST_INC_8);
SetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
&spi_recive_data,UDMA_SRC_INC_NONE,(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);
And I send data like below:
while(1)
{
to.tv_sec = 0;
to.tv_usec = 1000;
SL_FD_ZERO(&rset);
SL_FD_SET(iSockID, &rset);
max_fd = iSockID;
for(i=0; i<5; i++)
{
if(client_fd[i] > max_fd)
max_fd = client_fd[i];
if(client_fd[i]>0)
SL_FD_SET(client_fd[i], &rset);
}
ret = sl_Select(max_fd+1, &rset, NULL, NULL, &to);
if(ret > 0)
{
if(SL_FD_ISSET(iSockID, &rset))
{
iNewSockID = sl_Accept(iSockID, ( struct SlSockAddr_t *)&sAddr,
(SlSocklen_t*)&iAddrSize);
if(iNewSockID<0)
{
continue;
}
//memset(recv_buf,0,BUF_SIZE);
if(iNewSockID)
{
UART_PRINT("Client conneted\r\n");
/*******************点亮指示灯*******************/
MAP_GPIOPinWrite(GPIOA0_BASE,0x20,0x00);
if(client_fd[client_num]>0)
{
sl_Close(client_fd[client_num]);
SL_FD_CLR(client_fd[client_num], &rset);
}
client_fd[client_num] = iNewSockID;
client_num++;
if(client_num>=5)
{
client_num=0;
}
}
}
for(i=0; i<5; i++)
{
if(client_fd[i]<0)
{
continue;
}
iNewSockID=client_fd[i];
if(SL_FD_ISSET(iNewSockID, &rset))
{
iStatus = sl_Recv(iNewSockID, recv_buf, TR_BUFF_SIZE, 0);
if( iStatus <= 0 )
{
UART_PRINT("Client disconnected\r\n");
sl_Close(iNewSockID);
client_fd[i] = -1;
if(client_num>0)
{
client_num--;
}
for(j=0;j<5;j++)
{
if(client_fd[j]>0)
{
break;
}
}
if(j==5)
{
MAP_GPIOPinWrite(GPIOA0_BASE,0x20,0x20);
}
}
else if(iStatus > 0)
{
//UART_PRINT("%d",iStatus);
while(spi_transfer_end==0x0a);
spi_transfer_end=0x0a;
SetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,iStatus+1,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
&g_ucRxBuff,UDMA_DST_INC_8);
SetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,iStatus+1,
UDMA_SIZE_8,UDMA_ARB_1,
&recv_buf,UDMA_SRC_INC_8,(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);
MAP_GPIOPinWrite(GPIOA1_BASE,0x20,0x00); //set low the INTR
spi_transfer_send_time=0;
while((spi_transfer_end!=0x00)&&(spi_transfer_send_time<1000));//
if(spi_transfer_send_time>=1000)
{
MAP_GPIOPinWrite(GPIOA1_BASE,0x20,0x20);
Report("over time");
}
spi_transfer_end=0x00;
//set transfer to recive data from the master spi
SetupTransfer(UDMA_CH30_GSPI_RX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
(void *)(GSPI_BASE + MCSPI_O_RX0),UDMA_SRC_INC_NONE,
&spi_recive_data,UDMA_DST_INC_8);
SetupTransfer(UDMA_CH31_GSPI_TX,UDMA_MODE_BASIC,1024,
UDMA_SIZE_8,UDMA_ARB_1,
&recv_buf,UDMA_SRC_INC_NONE,(void *)(GSPI_BASE + MCSPI_O_TX0),
UDMA_DST_INC_NONE);
}
}
}
}
if(spi_send_enable==0x0a)//if the spi recive data from the master spi.
{
for(i=0;i<5;i++)
{
if(client_fd[i]<0)
{
//ucRxBuff_ok[i]=0x00;
continue;
}
else
{
iStatus=sl_Send(client_fd[i], spi_recive_data,spi_send_data_num , 0);//1-1460 bytes message size in bytes. Range: 1-1460 bytes
if(iStatus<=0)
{
Report("sl_send err num:");
}
else
{
;//Report("sl_send success num:#%d#",ucRxBuffNdx_back);
}
}
}
spi_send_enable=0x00;
}
}
Another question:
When the cc3200 work with spi slave mode ,can it use software cs control.If it is ,can i use the cs as a general gpio.