AnsweredAssumed Answered

SPI and Ethernet Controller 28j60

Question asked by Rama on Dec 2, 2011
Latest reply on Oct 11, 2012 by wahl.rudolf
Hi everyone,
I'm starting with the stm32f100rb and trying to set up the communication with 28j60(SPI). As far as know the 28j60 only support the spi mode 0 and  run at frequencies of at least  8 MHz.

To compile with spi mode 0 I should use  SPI_CPOL_Low and  SPI_CPHA_1Edge.

But then I have a real mess trying to figure out  how to select the frequency
Let's show you some pieces of code: 

/* Enable SPI1 and GPIOA clocks */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
     /* Configure SPI1 pins: NSS, SCK, MISO and MOSI */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
     GPIO_Init(GPIOA, &GPIO_InitStructure);
     //SPI1 NSS 
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

     GPIO_SetBits(GPIOA, GPIO_Pin_4);   

     /* SPI1 configuration */ 
     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;                              
     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
     SPI_InitStructure.SPI_CRCPolynomial = 7;
     SPI_Init(SPI1, &SPI_InitStructure);

The external oscillator it's 8MHz but, if I'm not wrong, then it's increased by the pll through:

     #define SYSCLK_FREQ_24MHz  24000000
/* #define SYSCLK_FREQ_HSE    HSE_VALUE */
/* #define SYSCLK_FREQ_24MHz  24000000*/
/* #define SYSCLK_FREQ_36MHz  36000000 */
/* #define SYSCLK_FREQ_48MHz  48000000 */
/* #define SYSCLK_FREQ_56MHz  56000000 */
    #define SYSCLK_FREQ_72MHz  72000000

And finally wich SPI_BaudRatePrescaler should I choose depending on the previous frequency rank.

Every answer will be appreciate.