2005-01-06 02:22 PM
Is there anything wrong in my ST10 SPI driver
2005-01-05 07:36 PM
We use ST10 as the master and ST7 as the slave.
St7 driver is OK and can communicate with MPC561. But our ST10 SPI can connect with ST7. We check the polarity, phase and Baudrate, but no problem. Now we want to add time delay before and after transfer, but no effect. Is there any standard SPI driver code for ST10? I search the ST website and find nothing. ST10: /* ============================================================================ ========= */ /* spi_st.c - Communication Interface (SPI) */ /* ============================================================================ ========= */ #include ''reg276.h'' /* register definitions for st10f276*/ #include ''spi_ft10.h'' /* SPI control register definitions */ #include ''misc_ft10.h'' /* system code */ /*| |*********************************************************************** |**** ************* | | void QSPIInit(void) | |*********************************************************************** |**** ************* | | Description: | | Initiallize the QSPI. | | | | Input Parameters: | | None | | | | Return: | | None | | | |*********************************************************************** |**** ************* \*/ void QSPIInit(void) { P3 = 0x0000; // Pin Data Reg. DP3 = 0x2200; // P3.8 (MRST) - Input; P3.9 (MTSR) - Output; P3.13(SCLK) - Output SSCBR = SPI_2M_BaudRate; // Baud Rate Generation - 2M SSCCON = 0x4037; // Data Width = 8, SSCPH =1, SSCPO = 0, Master Mode, MSB first SSCCON |= 0x8000; // SSCEN = 1 to Enter Operating Mode P3 = 0x2300; // SSCPO=0, enable alternate data output P3.13=1 return; } /*| |*********************************************************************** |**** ************* | | U16 QSPIWriteRead(U08 device_cs, U16 data) | |*********************************************************************** |**** ************* | | Description: | | Write the command to spi device and read the data from spi device. | | Spi delay should follow the spec. | | | | Input Parameters: | | device_cs, data | | | | Return: | | Data received from spi device | | | |*********************************************************************** |**** ************* \*/ U08 QSPIWriteRead(U08 device_cs, U08 data) { U08 SPIReceiveData=0x0; device_cs=device_cs; /* ** Set P6.7 low,Enable Equizzer ** Enable SCCEN */ P6 &= 0x7F; SSCCON |= 0x8000; /* transfer data */ SSCTB = data; /* Wait untill receive and transmit finished,SSCRIC */ while ( ((SSCRIC & 0x0080) == 0x0) || ((SSCTIC & 0x0080) == 0x0) || ((SSCCON & 0x1000) == 0x1000) ); /*Get the correct received bytes*/ P6 |= 0x80; U16_Delay(6); SPIReceiveData= (U08)SSCRB; /* ** Close Equizzer ** Disable SCCEN */ SSCCON &= 0x7FFF; /* Disable SSCRIR and SSCTIR */ SSCRIC &= 0xFF7F; SSCTIC &= 0xFF7F; return (SPIReceiveData); } ST7: /*----------------------------------------------------------------------- Copyright 2003 - Visteon Corporation *** CONFIDENTIAL AND PROPRIETARY *** History: 20Oct03 S.Lv S7FIFR10 - ST7 FEPS-LESS IVFER Version1.0 Initial Version -----------------------------------------------------------------------*/ #include ''commonf12.h'' #include ''spif12.h'' //---------------------------------------------------------------- // void SPI_Slave_Initialize(void) // Description: // Initialize the SPI port // // Input Parameters: // None // // Return: // None //---------------------------------------------------------------- void SPI_Slave_Initialize(void) { // Clear the SSI bit in SPICSR SPICSR = 0x00; // Master bit = 0 => Slave mode enabled, (CPOL, CPHA) = (0, 0) SPICR = 0x40; return; } //---------------------------------------------------------------- // U8 Put_Get_Byte(U8 byte_to_send) // Description: // Send a byte to the primary microprocessor through the SPI. // Read a byte from SPI but return it. // // Parameters: // byte_to_send input - byte to put into the SPI // // Return: // U8 read from SPI // // Function Calls: //---------------------------------------------------------------- U8 Put_Get_Byte(U8 byte_to_send) { U8 Get_Spi_Data, Temp_Variable; // Send SPI output data and enable transfer SPIDR = byte_to_send; // wait until SPIF = 1 means transfer has been completed while((SPICSR & SPIF) == 0){} // Clear SPIF Flag Get_Spi_Data = SPICSR; // Get SPI input data Get_Spi_Data = SPIDR; return(Get_Spi_Data); }2005-01-05 11:52 PM
Hi,
I didn't focuse a lot in your program but you can refer to the discussion in the following link:http://mcu.st.com/modules.php?mop=modload&name=Splatt_Forums&file=viewtopic&topic=1903&forum=5
i think it is useful. Bye [ This message was edited by: Najoua on 07-01-2005 09:27 ]2005-01-06 02:22 PM
Yeah, it works. Thanks you
/* Disable SSCRIR and SSCTIR */ SSCRIR =0; SSCTIR =0; /* transfer data */ SSCTB = data; while (SSCTIR==0) { PatDog(); } SSCTIR=0; /* receive data*/ while (SSCRIR ==0) { PatDog(); } SPIReceiveData=SSCRB; SSCRIR=0;