cancel
Showing results for 
Search instead for 
Did you mean: 

problem with bspi

tonio_k74
Associate II
Posted on September 25, 2007 at 08:20

problem with bspi

2 REPLIES 2
tonio_k74
Associate II
Posted on September 25, 2007 at 06:16

Hello,

I use BSPI cell to send and receive data (8 or 16 bits). I have to put to low level a SS pin during sending or receiving.But I am unable to keep at low level this pin during transferts by read out CSR2 registers for status...I inspired from some examples, and finally I managed to do what I want but....only for speed transfert of APB1/6 (1Mhz in my case...). If I change this speed, SS goes back to high before the end of sending, and the slave doesn't understand the command...

Please could someone help me? You can find the main program just below:

/

#include ''71x_lib.h''

/************************************************************/

void Pause(TIM_TypeDef *TIMx,u16 time)

/************************************************************/

{

u16 x;

x=(u16) (24036/1000)*time-(14615/100);

TIM_Init (TIMx );

TIM_OCMPModeConfig ( TIMx, TIM_CHANNEL_A, x, TIM_WAVE, TIM_HIGH );

while(!TIM_FlagStatus (TIMx, TIM_OCFA));

TIM_FlagClear (TIMx, TIM_OCFA);

TIM_CounterConfig (TIMx, TIM_CLEAR);

}

int main (void)

{

u8 temp;

const u8 cs1=9;

#ifdef DEBUG

debug();

#endif

/******************Clock for Timer configuration*******************************/

RCCU_PCLKConfig (RCCU_RCLK_2); //APB2 clk=PCLK=12 Mhz

/********************clock for BSPI Conf***************************************/

RCCU_FCLKConfig (RCCU_RCLK_8); //APB1 clk = FCLK=6 Mhz

RCCU_PLL1Config (RCCU_PLL1_Mul_24, RCCU_Div_4); //RCLK=48 Mhz

while(RCCU_FlagStatus(RCCU_PLL1_LOCK)==RESET);

RCCU_RCLKSourceConfig (RCCU_PLL1_Output);

TIM_Init ( TIM3 );

/* Configure the TIM Prescaler */

TIM_PrescalerConfig ( TIM3, 0 );

/--------------------------------------------------------------------------------------- */

/* Configure GPI00 on mode Alternate function Push Pull */

GPIO_Config (GPIO0, 0x00FF, GPIO_AF_PP);

GPIO_Config(GPIO0,0x0001<

GPIO_BitWrite(GPIO0, cs1, 0x01);

/* -------------------------------------------

Configure BSPI0 as a Master

------------------------------------------- */

/* Enable the BSPI0 interface */

BSPI_BSPI0Conf(ENABLE);

/* Initialize BSPI0 */

BSPI_Init ( BSPI0 ) ;

/* Configure Baud rate Frequency: ---> APB1/60 */

BSPI_ClockDividerConfig ( BSPI0,60);

/* Enable BSPI0 */

BSPI_Enable ( BSPI0 , ENABLE );

/* Configure BSPI0 as a Master */

BSPI_MasterEnable ( BSPI0,ENABLE);

/* Configure the clock to be active high */

BSPI_ClkActiveHigh(BSPI0,ENABLE);

/* Enable capturing the first Data sample on the first edge of SCK */

BSPI_ClkFEdge(BSPI0,DISABLE);

/* Set the word length to 16 bit */

BSPI_8bLEn(BSPI0,ENABLE);

BSPI_FifoDisable (BSPI0);

Pause(TIM3,10);

while(!BSPI0->CSR2&BSPI_RFNE)

{temp = (BSPI0->RXR)>>8;}

while (!BSPI_FlagStatus (BSPI0, BSPI_TFE)); /* Wait until the Transmit FIFO is empty */

GPIO_BitWrite(GPIO0, cs1, 0x00);

BSPI_WordSend(BSPI0,0x46); /* Send data to Transmit buffer */

//while((!(BSPI0->CSR2&BSPI_RFF)));

while (!BSPI_FlagStatus (BSPI0, BSPI_RFF));

GPIO_BitWrite(GPIO0, cs1, 0x01);

/* Infinite loop */

while (1);

}

Thanks a lot

tonio_k74
Associate II
Posted on September 25, 2007 at 08:20

Hello

No ideas?

other thing : I put SS/ pin for BSPI0 (pin PO.3) to high since i use BSPIO as master as I saw in documentation. I drive a CS pin chosen in P0.7 location. I mean before I send a command, I put this pin to low, I would like to wait that data are sent (this stuff doesn't work...)and finally I put CS to high again...

Thanks for your help,

Antoine