/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Problem with SPI2 and GPIO on Primer2

Username:     
Password:     
             

Forum

# 1   2009-04-23 16:55:17 Problem with SPI2 and GPIO on Primer2

tial
New member
Registered: 2009-04-15
Posts: 2

Problem with SPI2 and GPIO on Primer2

Hi,

I am trying to develop a simple application which uses SPI2 to connect the STM32 to an external chip over the extension connector of the Primer2.

I am not using the hardware chip select, but pin PC4 instead (CX_ADC1 on extension connector).

I am seeing two problems:

1) PC4 GPIO is not responding on GPIO_WriteBit functions (The pin goes high, but only for a short time)
2) SPI is nog working (no clock signal and data generated when SPI_I2S_SendData function is called).

To further test this, i have made a very basic application which only initializes the SPI and Pin PC4, then tries to make pin PC4 high (does not happen), and then when the orange button is pressed sends a data byte over SPI (nothing happens on SCK or MOSI lines).

Please find my code for the application below.

Does anyone has some ideas on what i might be doing wrong?

Kind regards,

Tim

/*******************************************************************************
* Function Name  : Application_Ini
* Description    : Initialization function of Circle_App. This function will
*                  be called only once by CircleOS.
* Input          : None
* Return         : MENU_CONTINUE_COMMAND
*******************************************************************************/
enum MENU_code Application_Ini ( void )
   {
   if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0)
      {
      return MsgVersion();
      }
       RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE );
       RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
 
       SPI_InitTypeDef   SPI_InitStructure;
       SPI_StructInit(&SPI_InitStructure);
       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_16; /* min 8 at 72Mhz (step 5)*/
       SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
       SPI_InitStructure.SPI_CRCPolynomial = 7;
       SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
       SPI_Init(SPI2, &SPI_InitStructure);
       SPI_Cmd(SPI2, ENABLE);
       /* SSn Config (PC4) -------------------------------------------------------------*/
       GPIO_InitTypeDef GPIO_InitStructure;
       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
       GPIO_Init(GPIOC, &GPIO_InitStructure);
           
       GPIO_WriteBit(GPIOC, GPIO_Pin_4,Bit_SET);
     
   return MENU_CONTINUE_COMMAND;
   }

/*******************************************************************************
* Function Name  : Application_Handler
* Description    : Management of the Circle_App.
*
* Input          : None
* Return         : MENU_CONTINUE
*******************************************************************************/
enum MENU_code Application_Handler ( void )
   {

   // TODO: Write your application handling here.
   //       This routine will get called repeatedly by CircleOS, until we
   //       return MENU_LEAVE
if( BUTTON_GetState() == BUTTON_PUSHED )
    {
        BUTTON_WaitForRelease();
        BUTTON_SetMode( BUTTON_ONOFF_FORMAIN );
       
        while ((SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) != SET)&&(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET));
         
        GPIO_WriteBit(GPIOC, GPIO_Pin_4,Bit_RESET);
        SPI_I2S_SendData(SPI2, 0x05);
        GPIO_WriteBit(GPIOC, GPIO_Pin_4,Bit_SET);
       
        return MENU_Quit();
    }
   

   return MENU_CONTINUE;   // Returning MENU_LEAVE will quit to CircleOS
   }

/*******************************************************************************
* Function Name  : MsgVersion
* Description    : Display the current CircleOS version and the version needed
*                  exit to main menu after 4 secondes
*
* Input          : None
* Return         : MENU_CONTINUE
*******************************************************************************/
enum MENU_code MsgVersion(void)
   {
   int hh,mm,ss,ss2;
   
   DRAW_DisplayString(5,60,"CircleOS",17);
   DRAW_DisplayString(80,60,UTIL_GetVersion(),3);
   DRAW_DisplayString(5,34,NEEDEDVERSION,3);
   DRAW_DisplayString(40,34," required",12);
   
   RTC_GetTime(&hh,&mm,&ss);
   ss = ss + 4;                  // 4 secondes
   ss = ss%60;
   
   do
      {
      RTC_GetTime(&hh,&mm,&ss2);
      }while (ss2 != ss);           // do while < 4 secondes
   
   return MENU_REFRESH;
   }

Offline

 

# 2   2009-04-24 06:40:01 Problem with SPI2 and GPIO on Primer2

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Problem with SPI2 and GPIO on Primer2

For the SPI, I believe that the pins must be configured too. See the audio.c file that also uses (when recording SPI2).

Offline

 

# 3   2009-04-24 07:30:35 Problem with SPI2 and GPIO on Primer2

tial
New member
Registered: 2009-04-15
Posts: 2

Re: Problem with SPI2 and GPIO on Primer2

Hi Francis,

Configuring the SPI pins solved indeed the SPI problem. However I still have the problem that pinC4 only goes high for a short time (i want it to stay high).
Any ideas? Perhaps something else in CircleOS is using this pin as well?

Kind regards,
Tim

Offline

 

# 4   2009-04-24 07:38:35 Problem with SPI2 and GPIO on Primer2

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Problem with SPI2 and GPIO on Primer2

No... I don't see why CircleOS would use it (except if it has been used as debug pin and we forgot to remove the related fragment of code). Try 'Find in files' in the source files of CircleOS.

Offline

 

# 5   2009-04-24 08:09:49 Problem with SPI2 and GPIO on Primer2

Saulis
Member
From: Lithuania
Registered: 2009-04-09
Posts: 34

Re: Problem with SPI2 and GPIO on Primer2

Francis :

No... I don't see why CircleOS would use it (except if it has been used as debug pin and we forgot to remove the related fragment of code). Try 'Find in files' in the source files of CircleOS.

Hi Francis, do you say, that PC4 currently is used as debug? In mine project, I use it as EXTI, so no luck to program properly, primer2 hangs every time i launch my program...

Offline

 

# 6   2009-04-24 11:58:00 Problem with SPI2 and GPIO on Primer2

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Problem with SPI2 and GPIO on Primer2

No, I just said that I don't think that it is used (it would be a bug if it is used). Moreover, there is no reason for hanging ...

Offline

 

Board footer