We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

How to work with Omega2+ SPI correctly?



  • Hi to all.
    My device will contain Onion Omega2+ and STM32. I need to transfer big amount data (~50MB - processed .BMP files uploaded via web) from Omega to STM32. Also STM32 can transfer similar files from his USB flash to Omega for same processing.
    So I need a fast link between them. Now I am trying to use SPI for this. And have some difficulties with him.
    For development purposes I connect STM32F042 (SPI slave) to Omega2 (SPI Master) by 4 wires: nCS, SCK, MISO, MOSI.
    STM32 firmware simply echoes received bytes to UART (to PC for monitoring) and back to SPI (Omega should receive this bytes):

        uint8_t val = 0x00;
        while ( 1 )
        {
        	// PA4 -- nCS
        	while ( GPIO_ReadInputDataBit ( GPIOA, GPIO_Pin_4 ) == Bit_SET );
    
        	val = bbb = spi1_sendbyte ( val );
        	usart2_PutByte ( bbb );
        } // while
    

    In Omega I using python3.6 and python-spidev driver.
    SPI int code:

            ## instantiate the spi object
            # for Omega2 firmware v0.3.0 and up:
            self._spi = spidev.SpiDev ( 0, 1 )
            # for older firmware:
            # spi = spidev.SpiDev(32766,1)
            # set the speed
            self._spi.max_speed_hz = speed_hz
            # SPI mode - CPOL|CPHA
            # 0b01: CPOL==0, CPHA==0
            self._spi.mode = 0b00
            self._spi.bits_per_word = 8
            self._spi.lsbfirst = False          # MSB first
            self._spi.cshigh = True
    

    SPI now works at 24MHz (max for STM32F042 chip).
    If I send data via xfer function data:

    Send to SPI:
    00000000: 48 65 6C 6C 6F 20 66 72  6F 6D 20 4F 6D 65 67 61  Hello from Omega
    00000010: 32 20 53 50 49 0D 0A                              2 SPI..
    Read from SPI:
    00000000: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
    00000010: 00 00 00 00 00 00 00                              .......
    OK
    

    If xfer3:

    Send to SPI:
    00000000: 48 65 6C 6C 6F 20 66 72  6F 6D 20 4F 6D 65 67 61  Hello from Omega
    00000010: 32 20 53 50 49 0D 0A                              2 SPI..
    Read from SPI:
    00000000: 05 00 00 00 00 00 10 33  00 00 00 36 10 00 00 00  .......3...6....
    00000010: 33 30 19 00 00 00 00                              30.....
    OK
    

    I received some trash šŸ˜ž and Windows terminal on PC shows zero byte after each data byte: H<0>e<0>l<0>l<0>0 ....
    May be this happens due to half-duplex Omega's SPI?
    How to work correctly with SPI? Is there FULL SPI example instead some pieces of code at https://github.com/OnionIoT/python-spidev

    Thanks.


  • administrators

    @Pavel--Negrobov Any reason why you're sending the data back from the STM to the Omega over SPI?
    All of xfer, xfer2, xfer3 should be able to correctly write the data.



  • @Lazar-Demin said in How to work with Omega2+ SPI correctly?:

    @Pavel--Negrobov Any reason why you're sending the data back from the STM to the Omega over SPI?

    STM32 on target device will have it's own USB Flash, user can select .bmp file from it. Processing algorithms are same as for bmp files uploaded by web. I want to transfer file from STM to Omega for precesssing.



  • @Pavel-Negrobov did you ever find good resources or get it to work?? I have a similar project although with another SoC instead of STM


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.