CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

2nd consecutive SPI write hangs everytime...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SparkyEE



Joined: 15 Jun 2007
Posts: 7

View user's profile Send private message Yahoo Messenger

2nd consecutive SPI write hangs everytime...
PostPosted: Mon Jun 18, 2007 1:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 1:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 18, 2007 2:20 pm     Reply with quote

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

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Jun 21, 2007 8:42 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group