Topic : SPI problems in Slave Software mode operation.

Forum : ST7/STM8

Original Post
Post Information Post
March 3, 2010 - 11:33am
Guest

Hi,

my SPI code for parity bit control work well, but if let alone. If I add Lart, LT, ADC and all what I need, it dont work as it must be: ST7lite39 on REva 2.10 dont response ACK (0x06) or NACK (0x15) but repeat the input MOSI byte... it seems to be unwrittable the SPIDR register in that moment, because if I defeat SPI_PutByte nothing change...

Quote:

SPI_Init(SPI_BAUDRATE_128|SPI_ENABLE_IT|SPI_ENABLE, SPI_SLAVE_SW);

Polarity = 0
Phase = 1

SPI reception in Interrupt Mode
SPI transmission in Polling Mode

CODE wrote:

INT_ROUTINE(SPI_IT_Routine, SPI_IRQ_ID) {

int i = 0, j = 0;
unsigned char ASCII_parity[2] = { 0x06 , 0x15 }, temp;

DisableInterrupts;
SPI_IT_Function();

while(!SPI_IsReceptionCompleted()) ;
SPIByte = SPI_GetByte();
temp = SPIByte;
IO_Write( IO_PORT_A , IO_PIN_0, IO_DATA_TOGGLE );

// HERE THERE IS THE PARITY CHECK FUNCTION

SPI_PutByte( ASCII_parity[ j & 0x01 ] ); //PutByte 0x06 ACK if bit are OK or 0x15 NACK if bit arent OK
while(!SPI_IsTransmitCompleted()) ;

SPI_Clear_Flags();
EnableInterrupts;

}


Results right wrote:

>spi swap 42 (00101010)
received : spi in 0 (right: first value is 0)

>spi swap 43 (00101011)
received : spi in 21 (0x15 NACK for 00101010)

>spi swap 43 (00101011)
received : spi in 6 (0x06 ACK for 00101011)


Results wrong wrote:

>spi swap 42
received : spi in 0 (right: first value is 0)

>spi swap 43
received : spi in 42

>spi swap 43
received : spi in 43


What could I control? Any idea?

Thx.

Replies
Post Information Post
+1
0
-1
March 3, 2010 - 4:12pm
Guest

Hi,

for your knowledge:

it work with Master and Slave with SPI_Phase at 1. If you use SPI_Phase at 0 you could have problems.

I only had to give (SPI phase 1) by

Into PeriphInit wrote:

SPI_Init(SPI_BAUDRATE_128|SPI_ENABLE_IT|SPI_ENABLE, SPI_SLAVE_SW);
SPICR = SPICR | 0x04;

How could I use "CLK_PP_Value - Selects the clock polarity and clock phase" in it?
Program dislike it's use.

Thanks

+1
0
-1
March 5, 2010 - 11:04am
Raisonance Support Team

Hello Chiesa,

This problem looks very much processor-related, and we will only be helpful concerning development tools. I suggest that you turn to the ST support people in order to get help specific to your problem.

Regards,
Bruno

+1
0
-1
April 22, 2010 - 5:00pm
Guest

GremlinC5 wrote:
Hi I have some other problems using the SPI with buffer and interrupt.

When I have an interrupt, how could I use functions in the routine to fullfill the buffer, this mine code do nothing:

Quote:

INT_ROUTINE(SPI_IT_Routine, SPI_IRQ_ID){
unsigned char buffer[SPI_BUFFER] = {.............};

DisableInterrupts;
SPI_IT_Function();

SPI_GetBuffer( &buffer[0], SPI_HEADER ) ;
while(!SPI_IsReceptionCompleted()) ;
if(buffer[2] <= SPI_PAYLOAD_MAX) { //dont go out of bound!!!
SPI_GetBuffer( &buffer[0]+SPI_HEADER, buffer[2]);
while(!SPI_IsReceptionCompleted()) ;
}

SPI_Clear_Flags();
EnableInterrupts;
}

I could use SPI_GetByte but I couldnt use SPI_GetBuffer at yet.

Quote:

/*-----------------------------------------------------------------------------
ROUTINE NAME : SPI_GetBuffer
INPUT 1 : *PtrToBuffer - Starting address of the user buffer
INPUT 2 : NbOfBytes - Number of data bytes to be received
OUTPUT : None
DESCRIPTION : In interrupt driven mode, starts data bytes reception in ISR
COMMENTS : None
-----------------------------------------------------------------------------*/

Do I must init buffer in main with SPI_GetBuffer? To init Global Variables in Spi.c?
/*-----------------------------------------------------------------------------
ROUTINE NAME : SPI_IT_Function
INPUT : None
OUTPUT : None
DESCRIPTION : Data transmission and reception takes place in interrupt
subroutine for Interrupt driven without buffer mode.
COMMENTS : None
-----------------------------------------------------------------------------*/
And use in the ISR the function SPI_IT_Function? That automatically fill data in the buffer?

Please I'll become crazy :/

Thank you.

+1
0
-1
April 26, 2010 - 10:26am
Guest

Hi, what I could understand is that I must know before how many byte my cpu is receiving and pass a initialize "SPI_GetBuffer" to initialize the buffer reception.

After in the ISR of SPI I must use "SPI_IT_Function" to capture data input to the buffer (rx or tx as needed).

Is it right?

my code doesnt work for: wrote:
if (!(SPI_Err))
"with SPI_Err == 0x80"

The problem was removed writing a FlagClean function as first function in the SPI ISR to clean the interrupt bit in the register.

I'm modifying your SPI IT function to achieve my desired protocol... ;)

Thanks.