View previous topic :: View next topic |
Author |
Message |
SparkyEE
Joined: 15 Jun 2007 Posts: 7
|
2nd consecutive SPI write hangs everytime... |
Posted: Mon Jun 18, 2007 1:25 pm |
|
|
In the following code snipet, the 2nd SPI write hangs everytime. What in the spi_write routine might cause this? Something I'm doing?
Thx.
void write() {
BYTE address;
BYTE value;
BYTE discard;
printf("\r\nAddress 0x");
address = gethex(); // get address from user
printf(" Data 0x");
value = gethex(); // get address from user
address = address & 0x1F; // mask unused bits, boil down to address
printf ("\r addr data = 0x%2x 0x%2x \r",address,value);
spi_write(address); // write instruction byte
spi_write(value); // write data byte <--- HANGS HERE
printf ("\r SPI write complete\r");
}
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 18, 2007 1:35 pm |
|
|
Post your setup_spi() statement.
In fact, post a small but complete test program that demonstrates
the problem.
The reason for asking for this is, you may not have a setup_spi()
statement, or it may be incorrect. Also, the Wizard can put in a
setup_spi(FALSE); statement. You may have that statement after
your setup_spi() statement, but didn't notice it. That's why I want
to see a complete test program. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 18, 2007 2:20 pm |
|
|
More likely is that the spi_setup routine are given some incompatible parameters and now the spi port is running in slave mode instead of in master mode. The CCS documentation is not very clear on which parameters are to be used for the slave only.
Additionally it wouldn't hurt if the poster could mention the processor and compiler version he is using. |
|
|
SparkyEE
Joined: 15 Jun 2007 Posts: 7
|
|
Posted: Thu Jun 21, 2007 8:42 am |
|
|
setup_spi() was not used but rather..
#use spi(MASTER, MODE=1, FORCE_HW, BAUD=1000000, BITS=8, stream=SPI_STREAM)
FYI, I found the problem, I need to "read" the spi port in-between writes. I noticed that even SPI writes read data on the SDI pin. Odd behavior if you ask me.
FYI, I'm using the PICkit2 debugger with the 16F887 demo board. |
|
|
|