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

Please need help in communication spi to rs232 in pic 16F88

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



Joined: 21 Jul 2011
Posts: 2

View user's profile Send private message Send e-mail

Please need help in communication spi to rs232 in pic 16F88
PostPosted: Thu Jul 21, 2011 8:27 am     Reply with quote

Good I'm new to the forum! Bouncing and would need help with my project, which is in communication with a sensor which sends data in 16-bit SPI protocol. I welcome you to the PC, with RS232. One pic should do the conversion of data, SPI to RS232 for reception and RS232 to SPI. To request the data you want to send me the situation is as follows.

The pic using the 16F88 in which I have already tried the RS232 and does not have problem, until simulated in Proteus. But when I wanted to do something with SPI is not where to start, I saw Confused Sad Sad. Proteus spinnaker has a debugger, I connect it and I try to send some data to that device but that's someone nada. It's necessary to give me a hand with this project please. The sensor data from which I take is ADIS 16405!! If any interested party wants to look a bit to orient me as to what to do, I already thank you very much.

FOR THE MASTER
Code:

#include <16f88.h>
#fuses XT, NOWDT, NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)

int dato=0,valor=1;

void main()
{
set_tris_b(0x02);
setup_spi(SPI_MASTER | SPI_l_TO_h | SPI_CLK_DIV_16);
spi_write( valor );
delay_ms(500);
dato = spi_read();

}

FOR THE SLAVE
Code:

#include <16f88.h>
#fuses XT, NOWDT, NOPROTECT
#use delay(clock=4000000)
#use fast_io(b)

int nuevodato;

void main(){
set_tris_b(0xf2);

do{
   setup_spi(spi_slave | spi_l_to_h | spi_clk_div_16);     //configurar spi como esclavo
   
      if(spi_data_is_in()){    //si hay un dato en el spi
         nuevodato = spi_read();
           if(nuevodato==1){
           
              output_low(pin_b6);
              delay_ms(3000);
              output_high(pin_b6);
              delay_ms(3500);}
     
      }while(true);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19326

View user's profile Send private message

PostPosted: Thu Jul 21, 2011 3:55 pm     Reply with quote

Comments inline:
Code:

void main()
{
set_tris_b(0x02);
setup_spi(SPI_MASTER | SPI_l_TO_h | SPI_CLK_DIV_16);
spi_write( valor );
delay_ms(500);
dato = spi_read();

//Code drops off the end here and goes to sleep

}

/////Slave
void main(){
set_tris_b(0xf2);

do{
   setup_spi(spi_slave | spi_l_to_h | spi_clk_div_16);     //configurar spi como esclavo
   //Get rid of the clock setting - Slaves are clocked _by_ the master
   //Invalid configuration for a slave.

   //Move the setup _out_ of the loop. Continuously resetting is unnecessary
   //and may result in data being lost. Put this with the TRIS.
      if(spi_data_is_in()){    //si hay un dato en el spi
         nuevodato = spi_read();
           if(nuevodato==1){
           
              output_low(pin_b6);
              delay_ms(3000);
              output_high(pin_b6);
              delay_ms(3500);}
     
      }while(true);
}

Beware - see a very recent thread, the 16F88, only supports slave operation, not master on the SPI port. You need to make sure the SPI master is running in software mode.

Best Wishes
JSP10



Joined: 21 Jul 2011
Posts: 2

View user's profile Send private message Send e-mail

PLEASE NEED HELP IN COMUNICATION SPI TO RS232 IN PIC 16F88
PostPosted: Thu Jul 21, 2011 6:55 pm     Reply with quote

I've tried what you indicated, but has not solved my problem does not work, you may review and simulate it to check what is wrong? Also not clear to me how do to set it as slave PIC.
Also told me not to be used as Master? Or is misunderstood.
Thank you very much for your interest!
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