2006-09-13 12:22 AM
using the buffered spi perpherial
2006-09-05 03:32 AM
Folks has anyone used the FIFO on the BSPIO cells of the str7xx
Basically I can configure the device and send out single bytes/words but I am interested in getting the buffered (eg 10 word)part going. To outline what I am looking for clear tx fifo (eg start transmission till tx FIFO underflow) set Tx FIFO and RX FIFO same depth load fifo with suitable data (think I can do) start TX (the data in tx FIFO) detect when all data has been Txed ( rx FIFO full ? eg monitor flags) deselect the SPI device recover the data from the Rx FIFO (think I can do read bspin_rxr till flag set empty buffer) The device select is a gpio (a hardware choice not of my making) What is the best to detect all the data has been sent eg put a non data byte on the end of data in fifo and wait till fifo empty flag set etc or set the depth of the rx buffer the same as tx buffer and wait for the rx buffer full flag to be set Reading the ST data sheets can be rewarding as a poke with a stick by the office gimp and at the moment its just not making sense. Anyone got any links to examples of other ST devices that use the same perperial or examples of code I may use [ This message was edited by: DanCurran on 05-09-2006 16:41 ] [ This message was edited by: DanCurran on 05-09-2006 17:20 ] [ This message was edited by: DanCurran on 05-09-2006 17:23 ]2006-09-05 05:30 AM
If you are not using ST's C libraries, the code can still give you a good idea of what is going on. Features are often used here even though they are not necessarily defined in the datasheets. You can download the source from
http://mcu.st.com/mcu/download2.php?file=str71xlibstd.zip&info=STR7 Software STR71x&url=http://www.st.com/stonline/products/support/micro/files/str71xlibstd.zip
for the STR71x.2006-09-13 12:14 AM
Folks just to help out others I have included a bit code that I find works pretty well on Txing out data and I am finisheing off the getting and collecting the rxed data.
dependant upon the amount of data to send out it either sets the buffers up as 16 bit or 8 bit and fires off whats in the FIFO It looks quite strange on the scope eg 1 - 10 bytes are send with 8 bits words 11 - 20 are a combination of both eg even is 16 bit the odd end byte is an 8 bit word. I am sure you can get the picture. Feel free to comment its allways interesting to hear others views Dan void SPIMessage(T_SPI_DEVICE bDevice,U8 *pbData,U16 wDatatoSend,U8 *pbDataIn,U16 wDatatoRead) { U16 wTestFlag; U16 wTempValue; U16 wWordsToSend = 0; /***** Set up the baud rate ******/ if(bDevice == E_SPI_DEVICE_EEPROM) { BSPI_ClockDividerConfig (BSPI1, 24); /** fastest is 1Mhz for eeprom **/ } else { BSPI_ClockDividerConfig (BSPI1, 6); /** approx 4mHz for everything **/ } /***** *****/ if(wDatatoSend) { do { /****************** * Clear the FIFOs ******************/ BSPI_RcFifoDepth(BSPI1,0); BSPI_TrFifoDepth(BSPI1,0); /** Disable the Tx **/ BSPI_Enable (BSPI1, DISABLE); /************************************************************/ /*** Only sending single bytes messages ***/ /************************************************************/ if( wDatatoSend == 1) { wDatatoSend = 0; BSPI_8bLEn ( BSPI1, ENABLE ); BSPI_TrFifoDepth(BSPI1,1); BSPI_RcFifoDepth(BSPI1,1); wTempValue = BSPI1->RXR; wTempValue = BSPI1->RXR; wTestFlag = *pbData; wTestFlag = (wTestFlag << 8); BSPI1->TXR = wTestFlag; wTestFlag = BSPI1->CSR2; spi_coms_chip_select(bDevice, C_DEVICE_ACTIVE); BSPI_Enable ( BSPI1, ENABLE ); do { wTestFlag = BSPI1->CSR2; wTestFlag &= BSPI_RFF; }while( wTestFlag != BSPI_RFF); wTestFlag = BSPI1->CSR2; spi_coms_chip_select(bDevice, C_DEVICE_INACTIVE); wTempValue = 1; } else if(wDatatoSend < 11) { /************************************************************/ /*** Only sending 0 to 10 bytes messages ***/ /************************************************************/ BSPI_8bLEn ( BSPI1, ENABLE ); BSPI_TrFifoDepth(BSPI1,(wDatatoSend)); BSPI_RcFifoDepth(BSPI1,(wDatatoSend)); for(wTempValue = 0;wTempValue < wDatatoSend;wTempValue ++) { wTestFlag = BSPI1->RXR; } /*** copy data to tx FIFO ***/ for(wTempValue =0;wTempValue < wDatatoSend;wTempValue++) { wTestFlag = *pbData; wTestFlag = (wTestFlag << 8); BSPI1->TXR = wTestFlag; pbData ++; } wDatatoSend = 0; spi_coms_chip_select(bDevice, C_DEVICE_ACTIVE); BSPI_Enable ( BSPI1, ENABLE ); do { wTestFlag = BSPI1->CSR2; wTestFlag &= BSPI_RFF; }while( wTestFlag == 0x00); spi_coms_chip_select(bDevice, C_DEVICE_INACTIVE); wTempValue = 1; } else { BSPI_8bLEn ( BSPI1, DISABLE ); if(wDatatoSend >= 20) { wWordsToSend = 10; wDatatoSend -= 20; } else { wWordsToSend = (wDatatoSend/2); wTempValue = (wWordsToSend*2); if( wTempValue < wDatatoSend) { wDatatoSend -= wTempValue; } else { wDatatoSend = 0; } } /** Less data than the size of the FIFO **/ BSPI_TrFifoDepth(BSPI1,wWordsToSend); BSPI_RcFifoDepth(BSPI1,wWordsToSend); for(wTempValue = 0;wTempValue < (wWordsToSend+1);wTempValue ++) { wTestFlag = BSPI1->RXR; } /*** copy data to tx FIFO ***/ for(wTempValue =0;wTempValue < wWordsToSend;wTempValue++) { wTestFlag = *pbData; wTestFlag = (wTestFlag << 8); pbData ++; wTestFlag |= *pbData; BSPI1->TXR = wTestFlag; pbData ++; } spi_coms_chip_select(bDevice, C_DEVICE_ACTIVE); BSPI_Enable ( BSPI1, ENABLE ); do { wTestFlag = BSPI1->CSR2; wTestFlag &= BSPI_RFF; }while( wTestFlag == 0x00); if(wDatatoSend == 0x00) { spi_coms_chip_select(bDevice, C_DEVICE_INACTIVE); } wTempValue = 1; } /*******************************************************************/ /*** we clocked something out so make sure we get the response ****/ /*******************************************************************/ do { wTempValue = BSPI1->RXR; wTempValue = (wTempValue>>8); *pbDataIn = wTempValue; pbDataIn ++; wTestFlag = BSPI1->CSR2; wTestFlag &= BSPI_RFNE; }while( wTestFlag == BSPI_RFNE); /*********************************************************************/ }while(wDatatoSend); } /*********************************************************************************************** * ************************************************************************************************/ if(wDatatoRead) { BSPI_BufferReceive(BSPI1,pbDataIn,wDatatoRead); spi_coms_chip_select(bDevice, C_DEVICE_INACTIVE); wTestFlag = BSPI1->CSR2; wTestFlag &= BSPI_RFNE; if(wTestFlag & BSPI_RFNE) { do { *pbDataIn = BSPI1->RXR; pbDataIn ++; wTestFlag = BSPI1->CSR2; wTestFlag &= BSPI_RFNE; }while( wTestFlag & BSPI_RFNE); } } }2006-09-13 12:22 AM
folks beware of some of the comments because they don't make sense. I haven't allways had enough coffee to get it right.
there is also a lot of debug code eg unnecessary instructions etc and overkill etc I am aware the data clocked in will be wrong and that is my next step to fix. [ This message was edited by: DanCurran on 13-09-2006 13:07 ]