Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SPI Help on pic16f1824

Status
Not open for further replies.

Delisaber

Member
Hello everybody,

Im trying SPI example. I can send data from master to slave but when I want read data from slave data is 0 always. I checked SCK pin. when Im sending SCK is generating clock pulse but when Im reading there is no. how it must be ? what should I do for read from slave.
Thank u
 
hi,
Which programming language are you using.??
 
Are you using ASM? Reading and writing are one and the same... The serial comunication is a ring The master clocks into the slave as the slave clocks back... The first byte sent from the slave is a dummy.

Can you post your code!
 
and here is code
Code:
void spi_setup(void)
{
    SSP1STAT = 0b00000000;
    SSP1STATbits.CKE = 1; 
    SSP1CON1 = 0b00000000;
    SSP1CON1bits.CKP = 0;
    SSP1CON3 = 0;
    SSP1ADD = 0; 
    TRIS_SDI=1;
    TRIS_SDO=0;
    TRIS_SCK=0;
    TRIS_CS=0;
    SSP1CON1bits.SSPEN = 1; 
}

unsigned char spi_transfer(unsigned char data)
{
    CS = 0;
    SSP1BUF = data;
    while( !SSP1STATbits.BF );
    CS = 1;
    SSP1STATbits.BF = 0; 
    return SSP1BUF;
}

Im newbie in MCU :)

here Im sending some data to slave and after slave is sending answer to me. it should come to SSP1BUF I think ?
 
pickit3 and 16f1824 Im using. XC8 has but I couldnt do it. on internet I found something and this code works good for send.
 
The send and receive happen at the same time; i.e. as the data to be sent (which may be a dummy byte, e.g. 0) is clocked out, the data to be read is clocked in. So to read a byte, you have to send one. Once the master has finished sending a byte, it will have finished receiving a byte also.
 
so when Im sending Im putting SSP1BUF.. and when slave send some data also it will come to SSP1BUF ? and also I checked SCK pin with oscilloscope. when Im sending there is pulse but after there is nothing. my question is ; it must be like this or when slave is sending must be clock pulses in SCK ?
 
so when Im sending Im putting SSP1BUF.. and when slave send some data also it will come to SSP1BUF ? and also I checked SCK pin with oscilloscope. when Im sending there is pulse but after there is nothing. my question is ; it must be like this or when slave is sending must be clock pulses in SCK ?
The master generates the SCK pulses, and the slave cannot send anything to the master without these pulses. For the master to pulse the SCK line, it must start a transmission (e.g. send something). At the same time the master is transmitting it is also receiving whatever the slave is sending.
 
The master generates the SCK pulses, and the slave cannot send anything to the master without these pulses. For the master to pulse the SCK line, it must start a transmission (e.g. send something). At the same time the master is transmitting it is also receiving whatever the slave is sending.

Thank you again to everyone,

Im working with CC113L.when I send some command to it it must reply me some answer.when Im sending there is SCK and also there is data in SDI. but it must be after my command. CC113L must see what I sent and after it will send answer. but after my data to it there is no SCK. but must be SCK yes ? so how I can generate SCK for read this data ?
 
You don't need to.

Send the command.... SSPxBUF will equal 0

Send a dummy command... SSPxBUF will equal answer.

There is only 1 command "SPI Transfer" read and write are as one.

To get the data just send a dummy command....
 
Thank you for help. I did like you told and data is coming. did anyone work with CC113L ever? because I think I have little problem with it :p
 
I used firstly CC115L for send packets and I did it. I can send and I can read from SmartRF software. Im trying read this packets from my card with CC113L. but I dont know where is problem..it came correct 2 times in 1000 test..Maybe I should know about how reading. It looks like so much complicated for me :)
 
Status
Not open for further replies.

Latest threads

Back
Top