For those who have an older version of the Discovery board. It has LIS302DL onboard instead of the LIS3DSH implemented in the video. You can simply tell the model by its shape, LIS302 has a rectangular package whereas LIS3 is square. The control register is a little bit different. Just replace spiTxBuffer[1] to 0x41 and you will get the data from the sensor.
Nice video.... Can you please make video on How we connect two STM32 board via SPI bus, because Its important in multiprocessor system. In multiprocessor system, need one STM board operate in SLAVE mode, and need proper communication steps between them. I unable to find useful information on google, no specific Tutorial on this using HAL library. Thanks again for your video
@@mutexembedded2206 Hi, I am working on project and I see there is state machine used, then I google but unfortunately I have not found useful tutorials on RU-vid or google regarding FSM finite state machine. There are many tutorials regarding C# and Python, but rare useful tutorials on C or embedded... Can you please make one video on FSM???? HOW Make FSM???? My another question is about main.c file in STM32.... What is use of assert() statements in there??? Thanks dear
Hi , loved your tutorial I had this one doubt .. I didn't understand the receive operation where you added 0x80 . Why do we have to make first bit of msb high ?? thank you
Good question, At some SPI IMUs, using the mask 0x80 enables Register Auto-Increment. Useful for acquiring X, Y and Z registers using start address of X and reading 6 consecutive bytes. Hope this helps, thanks :)
Hello there, first of all thank you for your video. I have a question about clock configuration. For the SPI Clock parameters you choose a prescaler of 16, and you mentioned that it is because the device is capable of 1 Mb/s. What is the reason behind this? which device you are referring, the accelerometer? I've been thinking about it without any successful answer of my own. Thank you,
Moises DS Hi, Spi devices have a maximum dataRate in which if you went behind it will start missing data. SPI peripheral is clocked by ABP1 Clock I think which is set to 16MHz for the above example, and I want to set speed to 1Mb/s thus a prescalar of 16. Hope this helps
Hi, I have been following your tutorial for quite some time and I must say it has been helpful. I will like to ask if I combine the UART configuration with this SPI configuration, Can I send the readings over UART? Like getting the data from the sensor using SPI and sending to serial using UART. Thank you.
Hello. Everythime I am trying to transmit over SPI I get hardfault. I am using L433RC, start with whole new project, but same. I have changed everything in cubeMX (pinout, frequency, datalength) and it still not working. Any advice? Thanks.
Hi, Hard fault is often caused when you are writing to a memory more that allocated. Uint8 buf[5] and you are writing 6 bytes to that memory. This will cause a Hard fault
@@mutexembedded2206 Yeah, but I declare uint8_t TxBuff[10] and in while loop I am calling HAL_SPI_Transmit(&hspi1, TxBuff, 2, 100) so it should be ok. I only declared TxBuff, call nss, Transmit and Delay...I must have missed something or there is some kind of bug...
Thanks for the video. can you do CAN bus example? some bookmarks: 2:28 setting SPI 1 in CubeMx 4:05 adding Tx and RX buffer to main 6:27 do: (reg_val | 0x80) to set device into read SPI operation. 8:13 debug it 8:49 view in STM studio 9:06 using the generated Project_name.axf file 10:56 using HAL_GPIO_EXTI_Callback() function 12:52 PART II - without use of CubeMx
I found the CAN Bus examle... STM32F4 Discovery board - Keil 5 IDE with CubeMX: Tutorial 33 - CAN Bus - RU-vid ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ar3I38lCLT4.html Thanks.
I wanted to make this comment, I tried using the HAL_SPI_Transmit(&hspi3, txSpiBuffer, 1, 50); and HAL_SPI_Receive(&hspi3, rxSpiBuffer, 1, 50); but it didn't work for me. I checked it using a logic analyzer and observed that the MOSI, and MISO were coming at the same time so I used a different command listed below and it worked fine. The process is pretty much the same except the TX and RX are done simultaneously. The device I was reading and writing to was an RC522 RFID device. I also was using a Nucleo-F767ZI board, where I soldered in male connectors giving me access to all the pins. //******SPI Receive start*********// //1. Bring Slave Select Line to Low HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); //2. Transmit address register //3. Receive data. txSpiBuffer[0] = 0x1F|0x80; //address for Read. txSpiBuffer[1] = 0x00; HAL_SPI_TransmitReceive(&hspi3, txSpiBuffer, rxSpiBuffer, 1, 50); //4. Bring slave select high HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); //******SPI Transmit end*********//
rwbazillion This is correct for Full duplex slaves.. But usually most external devices don't do that.. because they need to read your full command first.
The stm32cube framework & stm32cube HAL option is not available in my keil software, what Should i do. software (Keil uVision5 2013-2019 arm) please Reply
@@mutexembedded2206 I am new to this software & STM32. I searched but could not understand, Can you provide link. I have installed the package in column STM32F103C8.
Good video but it would be nice if u upload a reference material like explaining overall work flow of this prjt , block diagram to get overview of this prjt and maybe main.c
Hello, Thank you very much for the tutorials. I've tryed to implement a master slave comunnication between two Discovery boards but failed. Would you please be so kind to help us with this?
@@mutexembedded2206 my e-mail is eduardoavila1m@gmail.com I've got some interesting projects to do. If you are interested please send me an email and we can talk! Thanks
SIr i was trying to code this without MX on that without the External Interrupt i can get output on debugging in keil.....but with the external Interrupt i cant get output in STM STUDIO and LED is not toggled I checked the code properly it was all set....Please assist me to solve this problem!
Hello Mr. I want to use an SPI to transer a message between an STM32F4(master) and a STM32F4(slave), i'have trayed but failed, Would you please to help us with this? thank you
Hello mate, Could you please tell us where exactly in the datasheets should we find the appropriate registers (like 0x20) ? what should we look for exactly ?
I'm a little bit confused by the (0x20 | 0x80). I'm aware that 0x20 is the register address. but when we *or* it with 0x80, the address changes to 0xA0, which is a totally different register, that is not even mapped in the register table (as far as I can tell), so I'm surprised that it works. So, How did we really know that ORing an address with 0x80 enables the reading of that address ? (given that we're eventually passing a totally different address as a parameter to the /receive/ function)
After some readings, it seems to be the convention of enabling the reading mode for a register. Pardon my ignorance. However, I'm still having trouble understanding the clock configuration. any guidance would be greatly appreciated.
Hey, I am trying to use SPI with an STM32F407 board as a Master like here in your Video and a Nano Arduino as a Slave. Do you have a Slave code as well for using SPI? Thank you.
5 лет назад
I am using Atollic TrueStudio. How can i create a project that includes such spi, hal library without CubeMx? (at 13.14)
thank you, sir. The led doesn't blink at all, I dont know what's the problem but when I debug it says EVALUATION MODE running with code size limit 32K, I dont know if that changes anything, thanks again.
hi, I have a question. Aren't you supposed to write &spiRxBuff instead of spiRxBuff ? I can't see how it works since it requires a pointer inside the function definition.
Hi , i followed same steps but spiRxBuff didn't recieve 0x11 on debugging mode when i added it to watch 1 , it remained 0x00 !!!!!!! , i use stm32f429i-disco
oh ok so it will be different , Thank u +MYaqoobEmbedded i am one of your fans , you helped me so much with your tutorials , i wanna implement a pedometer can i use the gyroscope to do it ? if no , how can i use an external accelerometer ?
Hi, Glad to know that you're finding the STM tutorials helpful. It is possible to do it with Gyroscope, I came across this paper that explain how to do that: www.researchgate.net/publication/257397688_A_Gyroscope_based_Accurate_Pedometer_Algorithm Hope this helps
If you are using a L3GD20 you need to Transmit 0x0f to the 20h register in order to be able to Receive data from the gyroscope. Everything else is the same, just type 0x0f when he puts 0x11 and it should work.
Hi sir, can you make a video on 4094 8bit shift register using SPI protocol because I'm facing some problem in this I have Stm32f4 discovery board Thanks
Hii sir m a big fan of ur tutorials n ur techniques ... Sir i need ur help actually m working on RFID using STM 32 and nothing is available on internet about RFID So can u help me or send me links about RFID code... Plzz sir
Nil Rockz Hi Nil, I have not used this device before.. but from a quick look at the datasheet, here is what u need to do: 1. Send 0x1N (were 1: start bit) N = SD, D2, D1, D0 SD: 1 for Single ended 0 for differencial. D2 to D0: To choose the channel from 0 to 7. So, for e.g. to read channel 0.. step 1: send 0x18 step 2: read 2 bytes step 3: extract data from the 2 bytes (10 bits,, 7 taken from first byte Lower bits, 3 taken from the second byte 3 higher bits) Hope this helps. GLo
Sorry for short details. I am using it as MSB out first so i thought 2 bits to be taken from first byte LSB and 8 bits from second byte..thanks for help. I will try with this
I want to use UART & SPI together (read data from accel data over SPI, transmit data over UART to TTL-USB converter). I have both tutorials working separately. Then in the GPIO_EXTI_Callback function, where I receive the accel data, I added a HAL_UART_Transmit command to try send the data to the TTL-USB converter. But it doesn't work. Can you please give some advice/steps on what I should do instead? Thanks
Hi Mark, This is because of HAL_UART_Transmit(), because this function uses HAL_Delay, but an EXTI interrupt temporarily blocks HAL_Tick until returned from callback. In short, Using HAL_Delay inside an interrupt callback will cause the system to loop forever.
Hi Mohamed Thanks for your help so far. I got this working (I think) collecting samples from the accelerometer and transmitting them using a Bluetooth UART board. But then I tried adding a counter from 0-255, so I can check if I'm losing samples, and I had an issue. The counter (as I have it implemented below) is incrementing 2 or 3 times for every iteration of the while loop, instead of just once. Counter iterates even when I call the UART_Transmit function, even though the ++counter is in the GPIO callback function. Can you help? Thank you very much. My program looks like this: uint8_t spiTxBuf, spiRxBuf, uartBuf; uint8_t readyFlag = 0; int counter = 0; main { inits; SPI_Transmit (reg 0x20, set datarate and enable X data); SPI_Transmit (reg 0x23, enable DRDY, set interrupt active high, enable interrupt 1); while(1) { if (readyFlag==1) UART_Transmit( (uint8_t *) counter ); UART_Transmit( uartBuf ); readyFlag = 0; } } GPIO_Config{SPI pins, UART pins, CS pins, Interrupt pins, enable ext interrupt, enable systick} SPI_Config{...} UART_Config{...} DMA_Config{...} EXTI0_IRQHandler{...} DMA1_Stream5_IRQHandler{...} SysTick_Handler{...} HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { SPI_Transmit( reg 0x29 | 0x80 ) SPI_Receive(spiRxBuf) memcpy(uartBuf, spiRXBuf) readyFlag = 1; if(counter==255) { counter = 0 } else {++counter} }
@@fatihe.1338 Yes, but if you look at the function details, it does Transmit-Receive internally but ignores received data. Most devices however, behave in Half-Duplex way, where you send, then you receive ignoring all dummy data in between. an easy example is the SPI tutorial I shared.
Salam Muhammad! i am following you since a long time and your videos are really helpful. i have a question: i am using an external ADC MAX144 and want to read data using SPI through STM32L452 using HAL. but in the datasheet of ADC no register value for reading data from ADC is mentioned. can you tell me how to read data from ADC using HAL. ??? thanks in advance. datasheet : datasheets.maximintegrated.com/en/ds/MAX144-MAX145.pdf