Тёмный
No video :(

STM32F4 Discovery board - Keil 5 IDE with CubeMX: Tutorial 9 SPI - Updated Nov 2017 

Mutex Embedded
Подписаться 22 тыс.
Просмотров 59 тыс.
50% 1

Опубликовано:

 

21 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 121   
@shinongmao1915
@shinongmao1915 3 года назад
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.
@cecilhlungwana4940
@cecilhlungwana4940 6 лет назад
Thank you.😊 You are right about students not having to use cubeMX. That has been my problem when doing assinments.
@kevinzhang7302
@kevinzhang7302 6 лет назад
This is ridiculously helpful. THANK YOU SO MUCH!
@arshadparekh8938
@arshadparekh8938 6 лет назад
thank you very much, please provide CAN PROTOCOL example in stm32f07VG using cubeMX with keil and have a nice day.
@unlimitedsystem6525
@unlimitedsystem6525 4 года назад
thank a lot sir,,,from indonesia... superelektricalgeekkkkkkkk.......
@vyasneshkumarniranjan1542
@vyasneshkumarniranjan1542 Год назад
Thanks a lot sir ☺️ they are really very helpful
@emreozturk8842
@emreozturk8842 5 лет назад
Thank you bro.The sensor on the STM32F411VE and STM32F429ZIT processors is probably different here.
@shinongmao1915
@shinongmao1915 3 года назад
Yes, LIS302DL vs LIS3DSH
@DuGuo17
@DuGuo17 6 лет назад
very helpful SPI, with DMA or Intrup
@radhey04ec
@radhey04ec 3 года назад
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
@mutexembedded2206 3 года назад
I will keep it in mind for next time
@radhey04ec
@radhey04ec 3 года назад
@@mutexembedded2206 Thank you so much dear...
@radhey04ec
@radhey04ec 3 года назад
@@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
@abhishekk.m.7514
@abhishekk.m.7514 5 лет назад
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
@mutexembedded2206
@mutexembedded2206 5 лет назад
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 :)
@naasikhendricks1501
@naasikhendricks1501 6 лет назад
Awesome keep it up!!!!!!
@bhuvaneshs.k638
@bhuvaneshs.k638 4 года назад
Make a habit of uploading code main.c in description it would be very helpful
@moises_ds
@moises_ds 6 лет назад
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,
@mutexembedded2206
@mutexembedded2206 6 лет назад
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
@suspe1370
@suspe1370 5 лет назад
@@mutexembedded2206 Hi, isn't LIS3DSH Maximum clock frequency 10Mhz, therefore max baud rate 10Mbit/s ?
@youngolutosin1658
@youngolutosin1658 5 лет назад
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.
@mutexembedded2206
@mutexembedded2206 5 лет назад
Yeah, you definitely should be able to do that.
@youngolutosin1658
@youngolutosin1658 5 лет назад
Thank you
@jakubstejskal6806
@jakubstejskal6806 4 года назад
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.
@mutexembedded2206
@mutexembedded2206 4 года назад
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
@jakubstejskal6806
@jakubstejskal6806 4 года назад
​@@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...
@yosefgreen4187
@yosefgreen4187 2 года назад
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
@yosefgreen4187
@yosefgreen4187 2 года назад
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.
@rwbazillion
@rwbazillion 6 лет назад
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*********//
@mutexembedded2206
@mutexembedded2206 6 лет назад
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.
@mfatihakal6635
@mfatihakal6635 6 лет назад
yanlış spi hacı.Choose spi1 dude
@fernando.liozzi.41878
@fernando.liozzi.41878 4 года назад
WOW, excellent! Thanks!!!!!!
@johnnypark5686
@johnnypark5686 6 лет назад
Hi, does the Nucleo-F767ZI has a MEMS accelerometer? I was attempting to debug the spiRxBuf however its value remained in 0x00.
@NehaYadav-qk6eb
@NehaYadav-qk6eb 5 лет назад
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
@mutexembedded2206 5 лет назад
Hi, Package installer in Keil I believe
@NehaYadav-qk6eb
@NehaYadav-qk6eb 5 лет назад
@@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.
@bhuvaneshs.k638
@bhuvaneshs.k638 5 лет назад
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
@EduardoAvilaH
@EduardoAvilaH 5 лет назад
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
@mutexembedded2206 5 лет назад
Yup,, it is on my list for next weekend tutorial. Already have one for this weekend to be released tomorrow.
@EduardoAvilaH
@EduardoAvilaH 5 лет назад
@@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
@sirajahmadzai4760
@sirajahmadzai4760 4 года назад
Quick question, whenever I add my array to "watch 1" in Debug mode, it adds it as a "uchar" instead of "uint8_t array"...does anyone know why?
@mutexembedded2206
@mutexembedded2206 4 года назад
Hi, do you still have the problem? You should be able to change display type if you right click on the variable in Watch. GL
@abderrahmenrami
@abderrahmenrami 6 лет назад
can you please do an example how to use the output data of the accelerometer out x,y,z and blinking the led by reading those values
@mutexembedded2206
@mutexembedded2206 6 лет назад
New Tricks Good one!
@0cassus
@0cassus 6 лет назад
Thank you.
@muruganandamm6189
@muruganandamm6189 3 месяца назад
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!
@yunadita121
@yunadita121 4 года назад
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
@yaseen1478
@yaseen1478 6 лет назад
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 ?
@mutexembedded2206
@mutexembedded2206 6 лет назад
Abdelrahman yaseen Hi Yaseen, You just need to look for Registers map/table in the spi device datasheet.
@yaseen1478
@yaseen1478 6 лет назад
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)
@yaseen1478
@yaseen1478 6 лет назад
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.
@ahmedakifhekimoglu
@ahmedakifhekimoglu 4 года назад
@@yaseen1478 i tried it with 0xA and it also gives the same answer as 0x20|0x80
@hellangel5530
@hellangel5530 5 лет назад
Thank you for this tutorial. Can you make a tutorial about STM32 and NRF24l01 using CubeMX??
@claudiatann2110
@claudiatann2110 Год назад
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)
@khaliltroudy9908
@khaliltroudy9908 4 года назад
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.
@hesamembedded710
@hesamembedded710 3 года назад
hi, I wanted to know, how to expand your project and do the same job on the y and z-axis, using the polling method!?
@vadimpanin1551
@vadimpanin1551 4 года назад
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.
@mutexembedded2206
@mutexembedded2206 4 года назад
Hi, array name is a pointer to the first element in C programming
@vadimpanin1551
@vadimpanin1551 4 года назад
MYaqoobEmbedded thank you so much for the answer. Now I get it.
@alaeddinebakkay7556
@alaeddinebakkay7556 6 лет назад
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
@mutexembedded2206
@mutexembedded2206 6 лет назад
Hi Ala, That's because the STM32F429i-disco does not have this MEMS accelerometer, it has the L3GD20 MEMs Gyroscope instead.
@alaeddinebakkay7556
@alaeddinebakkay7556 6 лет назад
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 ?
@mutexembedded2206
@mutexembedded2206 6 лет назад
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
@alaeddinebakkay7556
@alaeddinebakkay7556 6 лет назад
thank u so much +MYaqoobEmbedded
@alexderkach_
@alexderkach_ 5 лет назад
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.
@lebrinth7011
@lebrinth7011 5 лет назад
is it gonna be a problem if i connect the chip select pin to the gnd all the time ,and thanks for the tutorial , its great ,
@musicalbite7271
@musicalbite7271 5 лет назад
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
@shahrukhhussain2593
@shahrukhhussain2593 5 лет назад
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
@nilamv6003
@nilamv6003 6 лет назад
Thank you sir. Can you please give example for ADC through SPI...??
@mutexembedded2206
@mutexembedded2206 6 лет назад
Nil Rockz Hi Nil, Do you mean you have an external ADC that you need to interface with using SPI?
@nilamv6003
@nilamv6003 6 лет назад
Yes. I am using mcp3008 and stm32 in 8 bit spi mode.i get proper MSB but LSB changes from 0 to 128 directly
@mutexembedded2206
@mutexembedded2206 6 лет назад
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
@nilamv6003
@nilamv6003 6 лет назад
Isn't it 2 bits from first byte msb and 8 bits from second byte?
@nilamv6003
@nilamv6003 6 лет назад
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
@jjorgea.8972
@jjorgea.8972 4 года назад
Why SPI GPIOs are not initialized with AF, etc at GPIO_init() ?
@huseinafif8697
@huseinafif8697 4 года назад
nice..
@erwinlejeune3620
@erwinlejeune3620 5 лет назад
could you do a video to explain how to use the motion sensor of the stm32 with spi ?
@mutexembedded2206
@mutexembedded2206 5 лет назад
Hi, Yes, it is the next video on my list.. will be on in couple of days.
@erwinlejeune3620
@erwinlejeune3620 5 лет назад
@@mutexembedded2206 My man. Subscribed :p
@rjgonzalez8108
@rjgonzalez8108 6 лет назад
I was hoping you would do DMA for SPI.
@mohamadali6174
@mohamadali6174 5 лет назад
Nice
@14sulli14
@14sulli14 5 лет назад
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
@mutexembedded2206
@mutexembedded2206 5 лет назад
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.
@14sulli14
@14sulli14 5 лет назад
Ok, that makes sense. Can you give me a pointer on how I should implement the UART transmit when SPI receives new data? Thanks for your help.
@mutexembedded2206
@mutexembedded2206 5 лет назад
uint8_t txBuf[25]; uint8_t readyFlag=0; ... main... while(1) { if(readyFlag == 1) { UART_Transmit(txBuf, size); readyFlag = 0; //Reset Flag } } SPI_Callback() { memcpy(txBuf, spiBuf, size); readyFlag = 1; //Set ready Flag }
@14sulli14
@14sulli14 5 лет назад
That's great. Thanks a million. Will try now. Please keep up the tutorials, they're a massive help!
@14sulli14
@14sulli14 5 лет назад
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
@fatihe.1338 3 года назад
Can you explain how you can send dummy data and get garbage data via "Hal Function " ?
@mutexembedded2206
@mutexembedded2206 3 года назад
Hi, I am not sure what the question here.
@fatihe.1338
@fatihe.1338 3 года назад
@@mutexembedded2206 without sending dummy data to slave , how can you receive valuable data from slave?
@mutexembedded2206
@mutexembedded2206 3 года назад
@@fatihe.1338 Hi Fatih, You're right, SPI is meant to exchange DR (data register) between device and master serially.
@fatihe.1338
@fatihe.1338 3 года назад
@@mutexembedded2206 Is it possible to exchange datas by using "SPI_HAL_Transmit" Function
@mutexembedded2206
@mutexembedded2206 3 года назад
@@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.
@belloutamina999
@belloutamina999 5 лет назад
Hello thank for all, please provide the SCT013 (100a) szensor current with STM32CubeMX and IOT
@scylla3618
@scylla3618 5 лет назад
CAN YOU HELP ME TO GET ANGLE USING SPI COMMUNICATION FROM A1335 I AM USING STM32 AND KEIL
@chungnguyen6378
@chungnguyen6378 6 лет назад
Can you tell me, what purpose of the time out?
@hijojoy
@hijojoy 6 лет назад
spi with dma
@andresfelipeparragafuquene4848
Can make a example with Display Oled?
@mrfornitefilms6413
@mrfornitefilms6413 5 лет назад
CAN THIS work on STM32F401RE ?
@dajianghe
@dajianghe 3 года назад
Hi, can you share the source code?
@mutexembedded2206
@mutexembedded2206 3 года назад
I don't have it anymore unfortunately
@huseyinkoc7461
@huseyinkoc7461 6 лет назад
0x20 | 0x80 ? What does it mean? Which register or data?
@mutexembedded2206
@mutexembedded2206 6 лет назад
Hi, It means that we are accessing register 0x20 in read mode (+ 0x80 to set MSB high).
@huseyinkoc7461
@huseyinkoc7461 6 лет назад
Why is it necessary? +0x80? why do we set to msb high? I see accessing 0x20 register but I dont understand why we use or bitwise with 0x80?
@huseyinkoc7461
@huseyinkoc7461 6 лет назад
Because 0x20 | 0x80 = 0xA0 ? nothing any register like that
@ferdinvivian9336
@ferdinvivian9336 6 лет назад
Even I have the same doubt sir, can you please explain further sir
@ferdinvivian9336
@ferdinvivian9336 6 лет назад
in datasheet where it is said sir, If i make 0x20 register's MSB as 1 (i.e) 1000 0000 it is set to read mode
@unlimitedsystem6525
@unlimitedsystem6525 4 года назад
how to get black theme on keil??
@mutexembedded2206
@mutexembedded2206 4 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-qKuwMHLazyY.html
@nazarhussain2757
@nazarhussain2757 5 лет назад
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
@mustafaglnr8780
@mustafaglnr8780 5 лет назад
sHARE YOUR ALL CODE WİTH US?
@yunadita121
@yunadita121 4 года назад
test
Далее
STM32. Урок 20. SPI. Serial Peripheral Interface
40:20