SPI-3 wires

miki
Wed May 18, 2016 10:30 pm
Hi,
I need some help.I want to use 3 wire spi comm with a rf module.
I need to use MOSI pin, bidirectional for write and read .How can I do it ?I want to use HW spi .bitbaging I know to do it.
I have a mini maple board.

zmemw16
Wed May 18, 2016 11:00 pm
which rf module?

if you don’t supply the info to allow an answer, we can’t.

at a first guess, try google with arduino + <module> + library e.g. arduino + nRF24L01 + library
also for 3 wire spi and arduino

stephen


WereCatf
Wed May 18, 2016 11:29 pm
zmemw16 wrote:at a first guess, try google with arduino + <module> + library e.g. arduino + nRF24L01 + library
also for 3 wire spi and arduino

zmemw16
Thu May 19, 2016 12:19 am
ok second guess

does st.com spi hardware support it?

which module ? sort of major unknown. bit like asking a builder for a fixed price?

stephen with a leaky roof


mrburnette
Thu May 19, 2016 1:08 am
This AppNote may be helpful
https://www.maximintegrated.com/en/app- … mvp/id/169

Seems if you aregoing to bit-bang anyway, it should be do-able.

This suggests a real-world use with Arduino

Ray


WereCatf
Thu May 19, 2016 1:26 am
zmemw16 wrote:does st.com spi hardware support it?

GrumpyOldPizza
Thu May 19, 2016 4:07 am
WereCatf wrote:zmemw16 wrote:does st.com spi hardware support it?

miki
Thu May 19, 2016 6:48 am
The RF module is not relevant for this discussion but it is not a secret.The 2.4Ghz A7105 uses 3wires spi ,SDIO pin is bidirectional.

There is some examples but use different STM32 chip with standard STM32 periph. library.I want to use with arduino with an STM32F103
http://www.ba0sh1.com/2014/05/31/howto- … plex-mode/

void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)
{
/* Check the parameters */
assert_param(IS_SPI_ALL_PERIPH(SPIx));
assert_param(IS_SPI_DIRECTION(SPI_Direction));
if (SPI_Direction == SPI_Direction_Tx)
{
/* Set the Tx only mode */
SPIx->CR1 |= SPI_Direction_Tx;
}
else
{
/* Set the Rx only mode */
SPIx->CR1 &= SPI_Direction_Rx;
}
}


racemaniac
Thu May 19, 2016 8:31 am
Well, now you start reading the STM32F103 reference manual to understand how the spi port works, what its registers do. Then you start looking into the libmaplecode/the library the spi library, and learn where you will have to make the changes to do the half duplex communication, and then you implement it, and share it with the rest of us :).

miki
Thu May 19, 2016 9:54 am
So you don’t know how to do it.
Anyway thanks.

zmemw16
Thu May 19, 2016 10:28 am
you have a roadmap, the route is up to you.
learn by doing, not by rote. that methodology applies in many areas.
one of my fellow students i still remember started every problem with the basic equations and demonstrated the
adage that the engineer knows both how and why it works.
horses and water thoughts also pop up.

stephen


miki
Thu May 19, 2016 10:52 am
Arduino was invented to be easy to use and faster coding not wasting valuable time.
The STM32 standary library is too low level to start aligning sheets of code only for initialize and toggle one single pin,For this reason the Arduino was perfect choice imo . But it is not useful to tell every Arduino user that he should looking in arduino core or arduino library and see what you can do over there.It looses the argument of using Arduino in the first place.
The thread here is related with code snippets so I think I was ontopic asking for a hint maybe some code than looking in maple library and see what you can find over there.
If you/anybody doesn’t know how what to do it or where to look, is not a shame.Of course Instead of continuing my project in arduino I need so check hot to modify maple library.
As I said before ,…thanks anyway.

WereCatf
Thu May 19, 2016 11:03 am
miki wrote:Arduino was invented to be easy to use and faster coding not wasting valuable time.
The STM32 standary library is too low level to start aligning sheets of code only for initialize and toggle one single pin,For this reason the Arduino was perfect choice imo . But it is not useful to tell every Arduino user that he should looking in arduino core or arduino library and see what you can do over there.It looses the argument of using Arduino in the first place.
The thread here is related with code snippets so I think I was ontopic asking for a hint maybe some code than looking in maple library and see what you can find over there.
If you/anybody doesn’t know how what to do it or where to look, is not a shame.Of course Instead of continuing my project in arduino I need so check hot to modify maple library.
As I said before ,…thanks anyway.

GrumpyOldPizza
Thu May 19, 2016 11:46 am
miki wrote:The RF module is not relevant for this discussion but it is not a secret.The 2.4Ghz A7105 uses 3wires spi ,SDIO pin is bidirectional.

There is some examples but use different STM32 chip with standard STM32 periph. library.I want to use with arduino with an STM32F103
http://www.ba0sh1.com/2014/05/31/howto- … plex-mode/


racemaniac
Thu May 19, 2016 12:02 pm
miki wrote:So you don’t know how to do it.
Anyway thanks.

miki
Thu May 19, 2016 12:11 pm
I know that but GIO1 and GIO2 pin are busy with control PA/LNA so they are not available.
Thanks.

And It is not doing for me it is doing for us all Improving arduino spi code with half duplex bidirectional feature from the people who knows best the maple library and STSM32 “nuts and bolts”.
@WereCatf
If you don’t want(not payed,sick with your life whatever)or Arduino is not complete say you can’t , no need to offend me.I’m not a kid.I have a bigger arduino project in avr and I want to port it in STM32,I don’t want to use make file with STM32 standard libraries and a wrapper for Arduino files I have.If possible ok if not, it is my problem.

@racemaniac
I will do some tests when I get home. Thanks.

GrumpyOldPizza wrote:miki wrote:The RF module is not relevant for this discussion but it is not a secret.The 2.4Ghz A7105 uses 3wires spi ,SDIO pin is bidirectional.

There is some examples but use different STM32 chip with standard STM32 periph. library.I want to use with arduino with an STM32F103
http://www.ba0sh1.com/2014/05/31/howto- … plex-mode/


GrumpyOldPizza
Thu May 19, 2016 12:22 pm
miki wrote:I know that but GIO1 and GIO2 pin are busy with control PA/LNA so they are not available.

miki
Thu May 19, 2016 12:30 pm
Yes that half true but you forget the second part,
I think in the end I will stick with bitbanging.

GrumpyOldPizza
Thu May 19, 2016 12:33 pm
miki wrote:Yes that half true but you forget the second part,
I think in the end I will stick with bitbanging.

miki
Thu May 19, 2016 12:41 pm
First half and second half

miki wrote:

And It is not doing for me it is doing for us all Improving arduino spi code with half duplex bidirectional feature ……from the people who knows best the maple library and STSM32 “nuts and bolts”.


mrburnette
Thu May 19, 2016 1:16 pm
miki wrote:The RF module is not relevant for this discussion but it is not a secret.The 2.4Ghz A7105 uses 3wires spi ,SDIO pin is bidirectional.

There is some examples but use different STM32 chip with standard STM32 periph. library.I want to use with arduino with an STM32F103
http://www.ba0sh1.com/2014/05/31/howto- … plex-mode/
<…>
How can be implemented this one if possible. Bitbanging is the last option.


racemaniac
Thu May 19, 2016 1:34 pm
To be honest, i think that if he gave it a try, and came for us for help when trying but having a hard time, it’ll be doable and he’ll get some good help :).
I’ve very recently been working with the SPI port, and its current implementations (and have made my own implementation building further on libmaple code), so if he has problems, i can for sure help him out.
If i spend a weekend on it, i can probably also get it working myself (but i just don’t have the time to do that atm -_-).

Forums follow a certain karma: you’ll get as much respons as you’re showing effort. If your question is: “i want this, and you should make it for me”, then the answer is “no”. If your question is “i’m trying to get this to work, but i’m stuck here, or don’t understand how that works”, you’ll get help from people who’ve been doing the same thing and know it better than you :).
Atm he’s pretty much asking the first thing, and i’ve got my own projects & code to care about, so i don’t have the time to implement that. If he’s stuck in implementing it himself, i’ve got a lot of experience with those things i’d love to share :).


miki
Thu May 19, 2016 1:41 pm
Wow,…. I managed to get out 3-rd page out of you guys.That means there is some interest. Lol!
I read briefly the reference.It seems easy to implement at a lower level.I will post some code soon.
Thanks!

mrburnette
Thu May 19, 2016 1:52 pm
miki wrote:
<…>
I read briefly the reference.It seems easy to implement at a lower level.I will post some code soon.
Thanks!

racemaniac
Thu May 19, 2016 1:54 pm
miki wrote:Wow,…. I managed to get out 3-rd page out of you guys.That means there is some interest. Lol!
I read briefly the reference.It seems easy to implement at a lower level.I will post some code soon.
Thanks!

martinayotte
Thu May 19, 2016 2:01 pm
BTW, @miki, I don’t think you’ve really mentioned which RF module you are using …
Which one is it ?

miki
Thu May 19, 2016 2:11 pm
I pull up some general code.I”m afraid going in maple.I’m used to work with avr registers.But it seems not much different.
Maybe I can combine arduino for init function and in the rest use manipulate registers.

uint8_t spi_read(){
uint8_t rx;
while(!(SPI_SR & (1<<TXE));
while(!(SPI_SR & (1<<BSY));
SPI_DISABLE();
SPI_SET_BIDIRECTIONAL();
SPI_ENABLE();
while(!(SPI_SR&(1<<RXNE));
rx=SPI_DR;
SPI_DISABLE();
SPI_SET_UNIDIRECTIONAL();
SPI_ENABLE();
return rx;
}

void SPI_ENABLE(){
SPI_CR1 |= (1<<SPE0);//enable SPI
}

void SPI_DISABLE(){
SPI_CR1 &= ~(1<<SPE0);//disable SPI
}

void SPI_SET_BIDIRECTIONAL()
{
SPI_CR1 |= (1<<BIDIMODE);
SPI_CR1 &= ~(1<<BIDIOE);//receive only
}

void SPI_SET_UNIDIRECTIONAL()
{
SPI_CR1 &= ~(1<<BIDIMODE);
}


GrumpyOldPizza
Thu May 19, 2016 3:26 pm
miki wrote:I pull up some general code.I”m afraid going in maple.I’m used to work with avr registers.But it seems not much different.
Maybe I can combine arduino for init function and in the rest use manipulate registers.

GrumpyOldPizza
Thu May 19, 2016 3:39 pm
GrumpyOldPizza wrote:miki wrote:I pull up some general code.I”m afraid going in maple.I’m used to work with avr registers.But it seems not much different.
Maybe I can combine arduino for init function and in the rest use manipulate registers.

miki
Thu May 19, 2016 4:01 pm
I don’t need to going faster 4.5Mhz on SPI2 div8 is enough.

GrumpyOldPizza
Thu May 19, 2016 4:08 pm
miki wrote:I don’t need to going faster 4.5Mhz on SPI2 div8 is enough.

miki
Thu May 19, 2016 4:43 pm
I have to test it when I’m getting back home.Yes start with lower speed.
Thanks.

GrumpyOldPizza
Mon May 23, 2016 6:03 pm
miki wrote:I have to test it when I’m getting back home.Yes start with lower speed.
Thanks.

miki
Tue May 31, 2016 4:50 pm
Sorry for delay ,
Yes I was able to test today and it is working ok Compile very well in arduino IDE 1.6.5
See below my code for SPI2

#include <SPI.h>
SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port

void initSPI2() {
//SPI_DISABLE();
SPI_2.end();
SPI2_BASE->CR1 &=~SPI_CR1_DFF_8_BIT;//8 bits format This bit should be written only when SPI is disabled (SPE = �0�) for correct operation.
SPI_2.begin(); //Initialize the SPI_2 port.
SPI_2.setBitOrder(MSBFIRST); // Set the SPI_2 bit order
SPI_2.setDataMode(SPI_MODE0); //Set the SPI_2 data mode 0
SPI_2.setClockDivider(SPI_CLOCK_DIV32); //// Slow speed (36 / 32 = 1.125 MHz SPI_2 speed) It is not worlking witvDIV16 and higher
}

uint16_t _spi_write(uint16_t command){
SPI2_BASE->DR = command;
while (!(SPI2_BASE->SR & SPI_SR_RXNE));
//SPI_2.transfer(command);//working also with this one only
return SPI2_BASE->DR;
}

uint8_t _spi_read(){

uint8_t rx=0;
SPI_DISABLE();
SPI_SET_BIDIRECTIONAL();
SPI_ENABLE();
while(!(SPI2_BASE->SR& SPI_SR_RXNE));
rx=SPI2_BASE->DR;
SPI_DISABLE();
SPI_SET_UNIDIRECTIONAL();
SPI_ENABLE();
return rx;
}

void SPI_ENABLE(){
SPI2_BASE->CR1 |= SPI_CR1_SPE;//enable SPI
}

void SPI_DISABLE(){
SPI2_BASE->CR1 &= ~SPI_CR1_SPE;//disable SPI
}

void SPI_SET_BIDIRECTIONAL()
{
SPI2_BASE->CR1 |= SPI_CR1_BIDIMODE;
SPI2_BASE->CR1 &= ~ SPI_CR1_BIDIOE;//receive only
}

void SPI_SET_UNIDIRECTIONAL()
{
SPI2_BASE->CR1 &= ~SPI_CR1_BIDIMODE;
}

The spi speed cannot be increased more than 1.125 MHz clock DIV32.The A7105 gives error byte readings.
Another thing I observed there is a pain in the ass to find a tutorial explaining how SPI port other than SPI1 to be set.The original maple HardwareSPI class is not usable anymore.


mrburnette
Tue May 31, 2016 7:22 pm
Another thing I observed there is a pain in the ass to find a tutorial explaining how SPI port other than SPI1 to be set.The original maple HardwareSPI class is not usable anymore.

http://www.stm32duino.com/viewtopic.php?t=278


miki
Tue May 31, 2016 7:31 pm
Thanks.

Yes I found how to implement it in your examples.


miki
Tue May 31, 2016 9:24 pm
The SPi it is working but it is too slow.
1.125 Mhz is too slow for the speed I need.I need faster at least double.

Vassilis
Tue May 31, 2016 11:37 pm
miki wrote:The SPi it is working but it is too slow.
1.125 Mhz is too slow for the speed I need.I need faster at least double.

miki
Wed Jun 01, 2016 12:02 am
I know how to set the the divisor and it is 36/4 -9Mhz
SPI2 afaik it is on 36Mhz bus on F10x.
The problem is not that ,I received garbage , if I increase the speed more than DIV32

RogerClark
Wed Jun 01, 2016 1:22 am
miki wrote:
The problem is not that ,I received garbage , if I increase the speed more than DIV32

miki
Wed Jun 01, 2016 1:31 am
The STM32 produced garbage at reading A7105 reg
However I played a little with the same code and I fix it .
Now I can go div4 and received normal.

I started liking the arduino with STM32 even if i had dig into maple library to play with regs.Anyway I did the same with avr’s.
It is very simple to make faster code ,compile and upload sketches.


RogerClark
Wed Jun 01, 2016 2:23 am
@miki

Can you post your updated code in case anyone else wants to use 3 wire SPI

Thanks

Roger


miki
Wed Jun 01, 2016 2:35 am
Yes of course.
How ever I still don’t fully understand why this one it is working at higher speed and previous not.
Maybe somebody can explain.The previous code is easy to explain.

here:
this one enables me DIV2.I tested with DIV2(18Mhz) and working.I can write and read A7105 regs at this speed.

uint8_t _spi_read(){
uint8_t rx=0;
SPI_DISABLE();
SPI_SET_BIDIRECTIONAL();
SPI_ENABLE();
//
SPI_DISABLE();
while(!(SPI2_BASE->SR& SPI_SR_RXNE));
rx=SPI2_BASE->DR;
SPI_SET_UNIDIRECTIONAL();
SPI_ENABLE();
return rx;
}


Leave a Reply

Your email address will not be published. Required fields are marked *