cancel
Showing results for 
Search instead for 
Did you mean: 

No Incoming data through MISO, What can my mistake be ?

KOzdi
Associate II

I am new in SPI protocol and trying to perform an application with LORA-Ra02 module via SPI protocol. I can send data through MOSI by considering DataFrame, CPOL, CPHA, rw bit of the frame but I cannot receive any data through MISO. I performed this application with both STM32 and Arduino to compare the differences. I want to share some picture and code to be understood better.

This is the picture of trying with Stm32f103, no incoming data :

0690X000006C9imQAC.jpg

This is the picture of trying with arduio, Datas must be like in this picture actually :

0690X000006C9irQAC.jpg

This is the information about SPI protocol of LORA Ra-02 module :

0690X000006C9iwQAC.jpg

This is the codes I wrote :

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_spi.h"
 
 
#define SPIx_RCC      RCC_APB2Periph_SPI1
#define SPIx          SPI1
#define SPI_GPIO_RCC  RCC_APB2Periph_GPIOA
#define SPI_GPIO      GPIOA
#define SPI_PIN_MOSI  GPIO_Pin_7
#define SPI_PIN_MISO  GPIO_Pin_6
#define SPI_PIN_SCK   GPIO_Pin_5
#define SPI_PIN_SS    GPIO_Pin_4
 
void SPIx_Init(void);
uint8_t SPIx_Transfer(uint8_t data);
void SPIx_EnableSlave(void);
void SPIx_DisableSlave(void);
 
uint8_t receivedByte;
 
void delay(unsigned long int time){
	
unsigned long c;
for(c=1; c<=time; ++c); // some delay
 
}
 
int main()
{
 
	// Initialization struct
    SPI_InitTypeDef SPI_InitStruct;
    GPIO_InitTypeDef GPIO_InitStruct;
 
    // Step 1: Initialize SPI
    RCC_APB2PeriphClockCmd(SPIx_RCC, ENABLE);
    SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
    SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
    SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
    SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
    SPI_InitStruct.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set;
    SPI_Init(SPIx, &SPI_InitStruct); 
    SPI_Cmd(SPIx, ENABLE);
 
    // Step 2: Initialize GPIO
    RCC_APB2PeriphClockCmd(SPI_GPIO_RCC, ENABLE);
    // GPIO pins for MOSI, MISO, and SCK
    GPIO_InitStruct.GPIO_Pin = SPI_PIN_MOSI | SPI_PIN_MISO | SPI_PIN_SCK;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(SPI_GPIO, &GPIO_InitStruct);
    // GPIO pin for SS
    GPIO_InitStruct.GPIO_Pin = SPI_PIN_SS;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(SPI_GPIO, &GPIO_InitStruct);
 
    // Disable SPI slave device
    SPIx_DisableSlave();
		
		
		receivedByte = SPIx_Transfer(0x22);
 
	
  while(1) 
	{
		
 
	
	}
}
uint8_t SPIx_Transfer(uint8_t data)
{ 
		uint8_t receivedOne;
	
		SPIx_EnableSlave();
		delay(1000);
    // Write data to be transmitted to the SPI data register
	
    SPIx->DR = data;
    // Wait until transmit complete
    while (!(SPIx->SR & (SPI_I2S_FLAG_TXE)));
	
	delay(1000);
	
    // Wait until receive complete
    while (!(SPIx->SR & (SPI_I2S_FLAG_RXNE)));
    // Wait until SPI is not busy anymore
    while (SPIx->SR & (SPI_I2S_FLAG_BSY));
    // Return received data from SPI data register
    receivedOne = SPIx->DR;
	
	  SPIx_DisableSlave();
 
		return receivedOne;
}
 
void SPIx_EnableSlave()
{
    // Set slave SS pin low
    SPI_GPIO->BRR = SPI_PIN_SS;
}
 
void SPIx_DisableSlave()
{
    // Set slave SS pin high
    SPI_GPIO->BSRR = SPI_PIN_SS;
}

What seems to be my problem ?

Thanks in advance !

16 REPLIES 16

>>What seems to be my problem ?

On the F1's program the MISO pin as INPUT FLOATING

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KOzdi
Associate II

I did what you said but the result is the same. I found an example on the web that someone else perform, he also program sck, miso and mosi as AF.

T J
Lead

did you make a custom board ?

are you sure you dont have Miso and Mosi swapped around ?

Can you check that the pin Miso actually connects from one chip to the other,

Check that with a meter, it should be 0Ohms approx.

KOzdi
Associate II

No, I am using stm32 dev board called Blue Pill. I am sure I connected MISO to MISO and MOSI to MOSI. I suppose the problem is in software side. If there seems to be no problem with the codes, I will try another slave device ?

If you are using any kind of compiler optimization then your delay function will be optimized out as useless code. Try making the "c" variable volatile or use a better delay function based on systick or any other timer.

KOzdi
Associate II

I put delay there at random I was just wondering if it has any effect or not. Without or with delay, Result doesnt change.

KOzdi
Associate II

I have tried everything but I cannot make it work

T J
Lead

check you pin numbers...

if you linked Miso to Mosi, then the scope would show that...

but if you connected the wrong pair of pins.., nothing will work.

did you check on the scope that the data is getting to the pin since you changed your configuration ?

KOzdi
Associate II

There is no problem with pin connections, I controlled pairs of pins, all is true, I thought that maybe device is broken-down I tried another lora, result was the same, Configurations seem true ; 8 bit, msb first, mode = 0, full duplex etc.

I never changed spi configuration, considering SPI protocol of LORA as it is seen above, configuration seems true

In arduino example, They use RESET and DI0 pin on LORA. Do those pins affect SPI communication ?