2008-02-13 03:02 AM
2011-05-17 12:49 AM
Me again... here's the code
// Enable peripheral clock for SSP1 and its GPIO port (GPIO3) SCU_APBPeriphClockConfig(__SSP1 ,ENABLE); SCU_APBPeriphClockConfig(__GPIO3 ,ENABLE); SCU_APBPeriphClockConfig(__GPIO1 ,ENABLE); GPIO_DeInit(GPIO3); GPIO_DeInit(GPIO1); // Gonfigure SSP1_CLK, SSP1_MOSI GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4| GPIO_Pin_6; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ; GPIO_Init (GPIO3, &GPIO_InitStructure); // IMPORTANT! NSS IPConnected must be disabled, or SPI enters loopback mode! GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; GPIO_Init (GPIO3, &GPIO_InitStructure); // Gonfigure SSP1_MISO pin GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; GPIO_Init (GPIO3, &GPIO_InitStructure); // Configure SSP1 for SPI Master, Mode 3, 8-bits, 12.5 MHz SSP_DeInit(SSP1); SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; SSP_InitStructure.SSP_Mode = SSP_Mode_Master; SSP_InitStructure.SSP_CPOL = SSP_CPOL_High; SSP_InitStructure.SSP_CPHA = SSP_CPHA_2Edge; SSP_InitStructure.SSP_DataSize = SSP_DataSize_8b; SSP_InitStructure.SSP_ClockPrescaler = 2; SSP_InitStructure.SSP_ClockRate = 0; SSP_Init(SSP1, &SSP_InitStructure); SSP_Cmd(SSP1, ENABLE); SSP_LoopBackMode(SSP1, DISABLE); // Enable GPIO0.1 (Chip Select for AT45DB161D) SCU_APBPeriphClockConfig(__GPIO0, ENABLE); GPIO_DeInit(GPIO0); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; GPIO_Init (GPIO0, &GPIO_InitStructure); // Configure MII_TXD1 SCU_APBPeriphClockConfig(__GPIO1, ENABLE); GPIO_DeInit(GPIO1); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Culprit right here! With this next line of code commented out, // the loop below reads the status register frrom the AT45DB161D properly. // Otherwise, it reads 0's. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GPIO_Init(GPIO1, &GPIO_InitStructure); while ( 1 ) { // Chip select GPIO_WriteBit ( GPIO0, GPIO_Pin_1, Bit_RESET ); // Read status register SSP_SendData ( SSP1, 0xD7 ); SSP_SendData ( SSP1, 0x00 ); while ( SSP_GetFlagStatus ( SSP1, SSP_FLAG_RxFifoNotEmpty ) == RESET ); x = SSP_ReceiveData(SSP1); while ( SSP_GetFlagStatus ( SSP1, SSP_FLAG_RxFifoNotEmpty ) == RESET ); x = SSP_ReceiveData(SSP1); // Chip deselect GPIO_WriteBit ( GPIO0, GPIO_Pin_1, Bit_SET ); } [ This message was edited by: spigeon on 13-02-2008 15:34 ]2011-05-17 12:49 AM
Okay, I am at my wit's end with this problem...
STR912FAW44 I am using SSP1 in master mode, Motorola format, to communicate with a serial flash device from Atmel. SSP1_MISO is connected to P3.5. Everything works fine. Then, I initialize the MAC controller, and bang! Can't read anything other than 0's on SSP1_MISO ! As soon as I configure the MAC contoller's P1.2 as an output pin (MII_TXD1), it seems like SSP1_MISO becomes disabled. Using a scope, I see a perfectly normal SPI transaction, and the correct data from the serial flash arrives at P3.5. But the FIFO contains 0's ! Funny observation: P1.2 (MII_TXD1) also happens to be an alternate input function for SSP1_MISO. It's almost like configuring P1.2 as an output pin causes not only P1.2 to be unusable for SSP1_MISO, but P3.5 as well... Anyone has an idea ??? I could post my code, but I'm not at work at this moment... [ This message was edited by: spigeon on 12-02-2008 14:25 ]2011-05-17 12:49 AM
Found the problem and I am rather angry that I had to spend a whole day looking for the answer.
When configuring P1.2 (MII_TXD2), it should be: GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; instead of : GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; IPConnected_Enable only applies to input pins - this raises the AltInput1 bit in the SCU_GPIOIN register. Therefore, I had SSP1_MISO enabled on P1.2 and on P3.5, which is illegal. But the damned line with IPConnected_Enable was taken from source code that came with my IAR compiler (web server example on the STR912-SK, using uIP), here: C:\Program Files\IAR Systems\Embedded Workbench 4.0\ARM\examples\ST\STR91x\STR912-SK-IAR\uip_webserver\modules\str912_enet.c