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.
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
also for 3 wire spi and arduino
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
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
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;
}
}
Anyway thanks.
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
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.
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.
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/
Anyway thanks.
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/
I think in the end I will stick with bitbanging.
I think in the end I will stick with bitbanging.
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”.
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.
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
.
I read briefly the reference.It seems easy to implement at a lower level.I will post some code soon.
Thanks!
<…>
I read briefly the reference.It seems easy to implement at a lower level.I will post some code soon.
Thanks!
I read briefly the reference.It seems easy to implement at a lower level.I will post some code soon.
Thanks!
Which one is it ?
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);
}
Maybe I can combine arduino for init function and in the rest use manipulate registers.
Maybe I can combine arduino for init function and in the rest use manipulate registers.
Thanks.
Thanks.
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.
Yes I found how to implement it in your examples.
1.125 Mhz is too slow for the speed I need.I need faster at least double.
1.125 Mhz is too slow for the speed I need.I need faster at least double.
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
The problem is not that ,I received garbage , if I increase the speed more than DIV32
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.
Can you post your updated code in case anyone else wants to use 3 wire SPI
Thanks
Roger
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;
}


