|
|
View previous topic :: View next topic |
Author |
Message |
JSP10
Joined: 21 Jul 2011 Posts: 2
|
Please need help in communication spi to rs232 in pic 16F88 |
Posted: Thu Jul 21, 2011 8:27 am |
|
|
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: 19535
|
|
Posted: Thu Jul 21, 2011 3:55 pm |
|
|
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
|
PLEASE NEED HELP IN COMUNICATION SPI TO RS232 IN PIC 16F88 |
Posted: Thu Jul 21, 2011 6:55 pm |
|
|
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! |
|
|
|
|
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
|