2011-12-01 09:03 PM
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 frequencyLet'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_HSE HSE_VALUE*/ #define SYSCLK_FREQ_24MHz 24000000#else/* #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 72000000And finally wich SPI_BaudRatePrescaler should I choose depending on the previous frequency rank.Every answer will be appreciate.2011-12-03 09:59 AM
Hi Rama,
I'm new to these STM32 chips but worked a lot with several other MCUs before so let me share you a general approach working with SPI. First, try to find a working SPI example - afaik there is an example for SPI in the STM32VL environment. Modify the code to have a forever loop sending out a dummy valued byte with a delay loop. Like this: while (1){ SPI_Write(dummy); for (int i=0; i<delay;i++){} } Next run the example and observe the SCK (SCLK) pin with your scope. If your SPI peripherial and your code is working then you'll see a nice pulse train. Measure the time between two rising edges and convert it to frequency. Compare this value to your CPU freq divided by the baudrate_prescaler. Experiment with changing this prescaler and observe the SCK frequency changes. These steps should be the firsts when you setup an SPI communication in an unknown enviroment. Later, when you are more comfortable with your code and environment, you don't need these tests.2012-10-11 01:47 PM
Hi Rama , did you get SPI and Ethernet Controller 28j60 working with STM32 discovery ?
I would be very happy if you could send me the code . best regards rudolf