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

AVR128 translation to PIC C?

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



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

AVR128 translation to PIC C?
PostPosted: Tue Jul 25, 2006 8:07 am     Reply with quote

Hi

I have the following C code for an AVR128:

Code:

SPDR = dataIn;
while((SPSR & 0x80)==0);
return(SPDR);


and have translated it to PIC C as follows:
Code:

DataReturned = spi_read(dataIn);
while(!(DataReturned & 0X80)){
    DataReturned = spi_read();
}
return(DataReturned);


Could some one please tell me if this is correct?
(I have never done SPI before).

Thank you in advance.
a.
Ttelmah
Guest







PostPosted: Tue Jul 25, 2006 10:19 am     Reply with quote

Simple answer. No.
There are two seperate values in the original code. 'SPDR', which is presumably the data I/O register, and 'SPSR', which is probably the 'status' register for the transfer. You are trying to use just one value in your 'converted' form. The original, is actually putting the value in 'dataIn', into the SPI transfer register, then waiting for the byte to be transferred, and then reading back the returned byte. SPDR, and SPSR, are hardware registers on the chip.
You can generate basically exactly the same code, if you define the hardware registers and bits (will depend on the PIC, which you don't say), but in fact you don't have to do this. All you need in CCS, to perfrom the same operation, is:

return(spi_read(dataIn));

The spi_read operation, automatically performs the 'wait', to clock the byte out, and won't return till this happens, and will then return the byte clocked back. Smile

Best Wishes
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Fri Jul 28, 2006 5:03 am     Reply with quote

Hi Ttelmah

Thank you!

Regards
a.
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