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

setup_spi throws an error

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



Joined: 12 Apr 2019
Posts: 3
Location: Louisivlle

View user's profile Send private message

setup_spi throws an error
PostPosted: Fri Apr 12, 2019 11:45 am     Reply with quote

I'm trying to build a fairly robust spi driver that I can then use in many projects but I'm running into some oddities.

Code:

int master = SPI_MASTER;

int mode = SPI_SCK_IDLE_LOW | SPI_XMIT_L_TO_H | SPI_CLK_DIV_2;

int speed = SPI_CLK_DIV_2;

int args = master | mode | speed;

setup_spi(args)

doesn't work
Code:

setup_spi(master | mode | speed);

doesn't work
but this
Code:

setup_spi(SPI_MASTER | SPI_XMIT_L_TO_H | SPI_SCK_IDLE_LOW | SPI_CLK_DIV_2);

does.
In both of the versions that don't work I'm getting "A numeric expression must appear here ::" as the error code at compile time

Ideally I'd like to use an enum and be able to pass in arguments to a more broad spiHwInit() function.

compiler version: 4.124
target: PIC24FJ256GA108
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 12, 2019 12:24 pm     Reply with quote

setup_spi() only works with constants.
shemminger



Joined: 12 Apr 2019
Posts: 3
Location: Louisivlle

View user's profile Send private message

PostPosted: Fri Apr 12, 2019 12:25 pm     Reply with quote

Well, that's a simple enough answer.

Can't say I like it though.

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 12, 2019 5:50 pm     Reply with quote

You can look at using #use spi() and streams. Define a different stream
name for each setup. Invoke the stream name when you call spi_xfer().
shemminger



Joined: 12 Apr 2019
Posts: 3
Location: Louisivlle

View user's profile Send private message

PostPosted: Fri Apr 12, 2019 6:04 pm     Reply with quote

Actually I think I'm going to step back and try to decide if I'm overengineering this.

Its quite likely, and probably in a way that's actually pretty bad in embedded, where how much program space I take making sure I can reuse a simple driver actually matters.

I already ran into this problem when I was playing around with using a homespun software_spi.

I managed to wind up with 7.8us clock cycles with my software spi because I spent so much time trying to make generic functions.
I cleaned it up with specific functions which means a lot less register hopping, and wound up getting it down to 800ns...

Thanks again for the input!
temtronic



Joined: 01 Jul 2010
Posts: 9114
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 12, 2019 6:21 pm     Reply with quote

The problem with 'generic' drivers is having to code for EVERY possibility. Heck there's 4 'modes' to begin with, then, hmm..speed.... then ...it gets ugly.
Usually you should KNOW exactly what devices will be on the board, so you just code for them. The driver may only use a fraction of the devices options, so the driver can be made smaller and more efficient.
Say you make a generic SPI driver and it works, 3 days later you add another device, but incorrectly point to the wrong function or some 'setup' uses negative logic(BTDT)....for the next 3 WEEKS you bash your head trying to find out what's wrong.......
I think some of the CCS bugs for new PICs might fall into this mess cause I can't figure out HOW they can get their compiler to understand every feature of every PIC...they usually get 99.99% right, but .001% wrong and the plane crashes.

Jay
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