View previous topic :: View next topic |
Author |
Message |
richi-d
Joined: 28 Aug 2007 Posts: 106
|
How to Readout SPI |
Posted: Wed Mar 05, 2008 7:00 am |
|
|
Hi all,
my problem is that the SPI BUS is hanging in the write_spi() Command...after enable the SSP interrupt
I first send the command to the other part that I want to read out, and then I send some dummy data to force a clock output...
Whats wrong?
Compiler 4.038
Code: |
#INT_SSP
void SPI_int()
{
SPI_IN = spi_read ();
SPI_GELESEN = 1;
}
....
void main()
{
SETUP_OSCILLATOR( OSC_32MHZ );
SET_TRIS_C(0x10);
*0xFC6 = 0x21; //SPI Clock/4
*0xFC7 = 0x40; //SPI ein
ENABLE_INTERRUPTS(GLOBAL);
.....
void Schreibe_SPI (KOMMANDO,DATEN)
{
output_low(CS);
NOP;
SPI_WRITE(KOMMANDO);
NOP;
SPI_WRITE(DATEN);
NOP;
output_high(CS);
}
void Lese_SPI (KOMMANDO, i)
{
output_low(CS);
NOP;
SPI_WRITE(KOMMANDO);
ENABLE_INTERRUPTS(INT_SSP);
for (x=0; x<=i; ++x)
{
SPI_WRITE(0xAA); //DUMMY - here the programm is hanging!!!!
}
output_high(CS);
while (SPI_GELESEN == 0)
{
NOP;
}
SPI_GELESEN = 1;
DISABLE_INTERRUPTS(INT_SSP);
}
......
Lese_SPI (0x0D,1);
IO_CONFIG = SPI_IN; |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 05, 2008 12:40 pm |
|
|
Are you trying to create an SPI slave ?
Look at these two CCS example files:
Quote: |
c:\Program Files\picc\Examples\Ex_spi_slave.c
c:\Program Files\picc\Examples\Ex_spi.c
|
This thread has code that demonstrates an SPI slave
but it's done using one board (just because it's a demonstration).
http://www.ccsinfo.com/forum/viewtopic.php?t=26888 |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Wed Mar 05, 2008 4:01 pm |
|
|
Hi PCM-
no I want to create a master:
I send a command to read out a register in the slave part. The master must create the clock for the slave... am I wrong?
I had a look to the examples- they are not very helpful because I cantĀ“find the include file: 9356spi.c ??? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 05, 2008 4:03 pm |
|
|
What's the manufacturer and part number of the SPI slave chip ? |
|
|
Ttelmah Guest
|
|
Posted: Wed Mar 05, 2008 4:50 pm |
|
|
There is very little point, in using the SPI interrupt, in a master device. This interrupt occurs, whenever a byte is clocked in. On a master, this occurs whenvever a byte is clocked. So each time you are writing the 0xAA 'out', you will immediately get an interrupt, to say a byte has been received. You might as well simply read the byte clocked immediately in the main code, after writing the 0xAA out. SPI_GELESEN, can never equal zero after this bit of code (since you have generated clocks, bytes will have been received...).
You _always_ receive the byte back, when you send a byte, even if it is garbage. It is up to the designers, to build the protocol, so that you know which byte in the sequence, is significant. Normally, you send initialisation bytes, and simply throw away the returns,and only after you have completed the initialisation, start reading returned data.
Best Wishes |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Thu Mar 13, 2008 1:05 am |
|
|
I found it out for myself:
in_data = spi_read(0);
Thats what I needed to know... |
|
|
|