Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:40 16 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Help matherp!

Author Message
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 11:31am 22 Feb 2016
Copy link to clipboard 
Print this post

Peter,
I needed a Cfunction routine to write data to the SPI port on a MX170, so I carved out the SPI code from your OLED driver. Things are working great (so far), but I may need to alter a couple of settings. This is where I need your help.

I would like to change the 8 bit output to 16 bit or maybe even to 32 bit (16 prefered). What bits need to be changed in config1 to achieve that? Also, I may wish to change the SPI port speed... is that possible or do I need a degree in quantum-hyper-mathematics?

Thanks,
Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10251
Posted: 11:48am 22 Feb 2016
Copy link to clipboard 
Print this post

To set to 16 or 32 bit you have to go to the SPI part of the MX170 manual page 167.

There is no short cut on this stuff the manual is the reference.

To set different speeds I always cheat - Use SPI OPEN in Basic to set the speed you want and then "PEEK" the SPIBRG register (address out of the manual - page 49). Then just copy the answer into your code - simples!
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 01:45pm 22 Feb 2016
Copy link to clipboard 
Print this post

Bummer! As always, a simple answer to what I thought would be hard and a difficult answer to what I thought would be simple. I was basing my question on page 197 of the PIC32 Peripheral Libraries for MPLAB C32 Compiler. Either way, both texts are way short of the total bits in config1. Looks like I'm going to be doing 8 bit writes for a while until I figure this out. Then again, 8 bits will work out fine for what I need right now, as most of the data is already in two separate bytes.

Thanks,
Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 03:16pm 22 Feb 2016
Copy link to clipboard 
Print this post

Ooops! I've got my bit/byte conversion all screwed up in my head. It didn't help, but at least now I have the proper tally on the bits.

--CurtisEdited by Justplayin 2016-02-24
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10251
Posted: 10:10pm 22 Feb 2016
Copy link to clipboard 
Print this post

  Quote  Looks like I'm going to be doing 8 bit writes for a while until I figure this out.


was trying not to spoonfeed

This one is really easy, just set bit 11 in SPI1CON and you are in 32-bit mode.

bit 10 set, bit 11 clear = 16-bit
bit 10 clear, bit 11 clear = 8-bit
bit 10 don't care, bit 11 set = 32-bit

We are not in "audio" mode so you can ignore AUDEN, it is always set to zero

Actually though it makes little difference to speed as we are using SPI in a blocking mode waiting for the bits to shift out before reloading
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 08:29am 23 Feb 2016
Copy link to clipboard 
Print this post

Peter,

I'm not looking for a "spoonfeed" which is why I asked about which bits to change. Even though it really is the same answer either way, I was interested in trying to related the bits with the rest of the configuration information. Your pointing me to the proper docs and page was a great help. That information showed me I was making a really stupid conversion mistake. What has me confused now is I know the SPI port is working in 8 bit mode, but as I read bits 10 and 11, it looks like it is configured for 32 bit mode.


#define SPICON *(volatile unsigned int *)(0xbf805800) //SPI config 1 register


0xbf805800 in binary would be:
1011 1111 1000 0000 0101 1000 0000 0000
.... .... .... .... .... ^... .... ....


Isn't that bit 11 set? Or, am I looking at this all wrong?

--Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 08:33am 23 Feb 2016
Copy link to clipboard 
Print this post

  Justplayin said   Peter,

I'm not looking for a "spoonfeed" which is why I asked about which bits to change. Even though it really is the same answer either way, I was interested in trying to related the bits with the rest of the configuration information. Your pointing me to the proper docs and page was a great help. That information showed me I was making a really stupid conversion mistake. What has me confused now is I know the SPI port is working in 8 bit mode, but as I read bits 10 and 11, it looks like it is configured for 32 bit mode.


#define SPICON *(volatile unsigned int *)(0xbf805800) //SPI config 1 register


0xbf805800 in binary would be:
1011 1111 1000 0000 0101 1000 0000 0000
.... .... .... .... .... ^... .... ....


Isn't that bit 11 set? Or, am I looking at this all wrong?

--Curtis


Have I not had enough coffee? Are you looking at the address rather than the data at that address?
Micromites and Maximites! - Beginning Maximite
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10251
Posted: 08:44am 23 Feb 2016
Copy link to clipboard 
Print this post

CircuitGizmos is absolutely correct.

The #define creates a variable label within the compiler where the contents of that variable are stored at the physical address 0xbf805800. Volatile tells the compiler that the contents may change while the code is running so not to optimise by taking a local copy i.e. read it afresh each time it is used.

So in Basic go SPI OPEN 1000000,3,8.
Then in Basic you can "print hex$peek(word &Hbf805800))" to read the contents of the register. If you do that you should see bit 11 isn't set.

Then try SPI OPEN 1000000,3,32 and peek again, it should now be setEdited by matherp 2016-02-24
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 08:59am 23 Feb 2016
Copy link to clipboard 
Print this post

Of course it's the address not the configuration I've been looking at. I see it now! I hate C !

Thank you both!

--Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2949
Posted: 10:47am 23 Feb 2016
Copy link to clipboard 
Print this post

Curt,

  Justplayin said   I see it now! I hate C ! --Curtis


Shouldn't that be

I C it now! I hate see? (I always thought C's logic looked backwards to me)

Curtis, I am pretty impressed at how quickly you have adapted to C.. I know I could never do it, or can I?

You have shamed me into giving it another go, the speed improvement you mentioned in PM to me sounds absolutely awesome.

Keep up the good work.

Regards,

Mick


Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 01:56pm 23 Feb 2016
Copy link to clipboard 
Print this post

  bigmik said  You have shamed me into giving it another go, the speed improvement you mentioned in PM to me sounds absolutely awesome.


Come on and join the fun Mick! In 30 days you can be just as lost as I am now with C.

--Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
Lou

Senior Member

Joined: 01/02/2014
Location: United States
Posts: 229
Posted: 03:37pm 23 Feb 2016
Copy link to clipboard 
Print this post

Mick,

Looks like you have just lost a beloved member of your family.
My condolences, I am very sorry.

Lou
Microcontrollers - the other white meat
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025