Porting code from AVR Atmega128?

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

I want to port from AVR to STM32CubeMx...
Please correct me if I'm wrong

 

STM32 :
/* Exchange a byte */
static
BYTE xchg_spi (     /* Returns received data */
    BYTE dat[1]     /* Data to be sent */
)
{
    while(HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
    HAL_SPI_Receive(&hspi2,dat,1,100);
    return dat[1];
}
 
AVR :
/* Exchange a byte */
static
BYTE xchg_spi (     /* Returns received data */
    BYTE dat        /* Data to be sent */
)
{
    SPDR = dat;
    loop_until_bit_is_set(SPSR, SPIF);
    return SPDR;
}

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow, out of left field.

 

Given the code snippet, it looks like a basic SPI primitive for the AVR.

 

If you want to do that on a different architecture from a different manufacturer, why aren't you asking on an ST forum?  Doesn't Atmel pay the freight to have this site, to promote Atmel products?

 

My quick answer is that it appears impossible to do SPI on an STM32 processor.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I write bare metal code on the stm32, so i have no idea of the hal functions. Best be doing some reading and testing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
    HAL_SPI_Receive(&hspi2,dat,1,100);

I lost interest there!

 

We all know that SPI is always a send AND receive process. A library that includes a specific receive() function suggests implementation by someone who didn't wholly "get" the whole SPI thing!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
A library that includes a specific receive() function suggests implementation by someone who didn't wholly "get" the whole SPI thing!

 

Or someone who wrote three functions, two of them convenience-variants of the third.

 

Sketchy:

SPI_Transmit(sendDataBuffer);
SPI_Receive(receiveDataBuffer);
SPI_Transceive(sendDataBuffer, ReceiveDataBuffer);

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://developer.mbed.org/users... : stm32xxx seems to have a lot of SPI variants . Detailed docs (without examples : receiving, transmitting, doing both,            software controlled/IT /DMA) can be found  at www.stmcu.com.cn/download?id=1632 , pages 497-505 out of 692 .... (I did not find any examples : maybe pages would get longer ).

 

edited : added the total number of pages of DM00122015.pdf (UM 1785)

Last Edited: Tue. Jan 19, 2016 - 12:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:

I want to port from AVR to STM32CubeMx...

To STM32 using HAL library. STM32CubeMX is a software to make the HAL codes for initializing the peripherals.

dbrion0606 wrote:

https://developer.mbed.org/users... : stm32xxx seems to have a lot of SPI variants ...

It depends on your STM32 MCU. F1? F2? F3? F4? F7?

 

I think best suggestion for bianchi77 is this:

Go to the page of your MCU in ST website.

Click on the "All" tab and download the HAL lib for your MCU

After finishing the download, go to this Address:

Projects\STM32F0xx_StdPeriph_Examples\SPI

And take a look at the examples.

 

And ask your questions here:

 

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx

 

There is a guy named Clive1. he always helps the users of STM32

 

Good luck!smiley

"One's value is inherent; money is not inherent"

 

Chuck, you are in my heart!

Last Edited: Tue. Jan 19, 2016 - 01:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"It depends on your STM32 MCU. F1? F2? F3? F4? F7?"

 

What does HAL mean? (it it were "Hardware Abstraction Layer", may be it would be  meant (at least, the long documentation)  to hide the STM32 number as much as possible, and only the way software is called is convenient, whatever the processor variant: at least, one could hope that -else, reading  long documentation for each and every processor would destroy forests...)