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

SPI-Problem send multiple bytes
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Wed Sep 26, 2018 2:09 pm     Reply with quote

what do you mean pic101 sticky? is this a simulation software?
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Wed Sep 26, 2018 2:14 pm     Reply with quote

I did not notice that. Of course, both can have the same mode. do I still have to send the 0x01 twice?
newguy



Joined: 24 Jun 2004
Posts: 1902

View user's profile Send private message

PostPosted: Wed Sep 26, 2018 2:49 pm     Reply with quote

Sterngleiter wrote:
what do you mean pic101 sticky? is this a simulation software?


He meant this: http://www.ccsinfo.com/forum/viewtopic.php?t=47549
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Wed Sep 26, 2018 11:04 pm     Reply with quote

You should not have to send 1 twice. It is being missed because of the wrong clock edge...
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Wed Sep 26, 2018 11:31 pm     Reply with quote

how should the right clock edge be so that I do not have to send a dummy
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:09 am     Reply with quote

The clock edges is wrong because you have different modes.
Also how is the select line wired on the slave?.

There is another issue, on the first 'dummy' transfer, this will _start_ at the instruction:

spi_xfer(0x01); //single 'send only' transfer to signal start

But, this transfer won't complete for several instruction cycles. So the delay here may be too short.

When you use:

val=spi_xfer(0x01);

This makes the instruction _wait_ for the physical transfer to complete before proceeding.

So, you can either add a dummy read to the first transfer, or wait for the transfer with:
Code:

   while (!spi_data_is_in())
       ;
   delay_us(50);


on this first transfer.


Last edited by Ttelmah on Thu Sep 27, 2018 12:17 am; edited 1 time in total
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:16 am     Reply with quote

As well as Master, CLK=PIN_C3, DI=PIN_C4, DO=PIN_C5
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:48 am     Reply with quote

That sounds completely wrong....

On you 18F4550, SDI is RB0, SDO is RC7, SCL is RB1, and SS is RA5.

The master SDO needs to go to the slave SDI, and the slave SDO to the master SDI.

You can use any pin you want for a master, but the slave _must_ connect to the actual hardware pins.....
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:51 am     Reply with quote

Why pic18f4550 ? I have pic18f8622

Last edited by Sterngleiter on Thu Sep 27, 2018 12:54 am; edited 1 time in total
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:52 am     Reply with quote

Pic18f8622
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:53 am     Reply with quote

I Know, MISO, MOSI , CLK , CS is right
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 1:12 am     Reply with quote

You have never told us the processor number for your slave....

The 8622, uses RD7 for SS.

It also has some quite nasty errata on SPI. :(
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 1:16 am     Reply with quote

I use SPI_1 , SS is the Pin_f7. Pin_D7 is for SPI_2
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 1:23 am     Reply with quote

Good.

The point is it's a classic case of omitting stuff. You posted code carefully 'leaving out' the processor part and not telling us how stuff is actually wired. Don't be surprised if we then query things when you do this....

A little table like:

MASTER SLAVE

SDO C7 SDI C4
SDI C4 SDO C7
CS C2 SS F7
SCK C3 SCK C3

Chip is PIC18F8622 clocked at?....
Sterngleiter



Joined: 07 Jan 2013
Posts: 90

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 1:38 am     Reply with quote

you're right. I should have written.
Pin_C5 is by SPI_1 Data out(SDO) Not c7.
I think the wiring is correct.
Master. SLave
pin_c3 (clk) —— pin_c3 clk
Pin_c4 (SDI) —— pin_c5 ( SDO )
Pin_c5 (SDO) —— pin_c4 ( SDI )
Pin_c2 ( CS) —— pin_f7 ( SS )
8mhz internal
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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