element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs High Throughput SPI traffic part 1b - SPI without Buffers
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 17 May 2016 6:13 PM Date Created
  • Views 981 views
  • Likes 9 likes
  • Comments 7 comments
  • educational_boosterpack
  • lcd
  • boosterpack
  • spi
  • mibspi
  • texas_instruments
  • microcontroller
  • hercules
  • launchpad
Related
Recommended

High Throughput SPI traffic part 1b - SPI without Buffers

Jan Cumps
Jan Cumps
17 May 2016

We know SPI as a 4*-wire protocol. But it doesn't have to be.

I'm checking high speed SPI data transfer with buffers, DMA and parallel data lines.

 

image

 

Let's analyse what the SPI cost is of my naive implementation, where I paint pixel by pixel.

 

SPI Traffic for a Single Pixel

 

Painting a single pixel on the LCD requires 8 SPI calls. In total we move 15 bytes.

The majority is spent on setting a draw window of 1 x 1 pixel. The paint command by itself just takes 2 bytes.

 

Code snippet

 

    _writeCommand(HX8353E_CASET);
    _writeData16(x0);
    _writeData16(x1);
    _writeCommand(HX8353E_RASET);
    _writeData16(y0);
    _writeData16(y1);
    _writeCommand(HX8353E_RAMWR);
    _writeData16(colour);

 

 

 

actionbytestotal
start point command1 byte1
coordinate x2 bytes3
coordinate y2 bytes5
end point command1 byte6
coordinate x2 bytes8
coordinate y2 bytes10
write data command1 byte11
write the pixel colour2 bytes13

 

The analyser trace looks like this:

image

And the protocol analyser tells us:

image

 

Almost 20 µS for a pixel. My SPI clock runs at 27.5 Mbits per second.

13 bytes per pixel is 1664 bytes for one line of 128 pixels.

2.6 ms per line (20µs x 128). 328 ms for the whole 128 x 128 bitmap.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

A Slightly Less Naive Approach

 

Let's try a first speed bump by setting the window to one line in stead of one pixel, and then push the data after that.

Unbuffered still. We are looping through the line and send a pixel at a time over SPI.

But we only send the positioning and windowing bytes (11 of the 13) only once per line.

A saving of 1397 bytes per single line.

 

Code snippet:

void setBitmapInOneThrow(bitmap_t *bmp) {
  uint32_t xx, yy;


    for (yy = 0; yy < bmp->height; yy++) {
        _setWindow(0, yy, bmp->width, yy );
      loadBitmapInDMABuffer(bmp, yy);
        for (xx = 0; xx < bmp->width; xx++) {
        _writeData16(TXDATA[xx]);
        }
    }
}

 

 

We still spend the same time for these activities as in the previous implementation.

image

16 µS to get the LCD screen initialises. For a whole line now.

 

Beaming the full line of data, 128 x 2 bytes, took us 360 µS

 

image

 

The total time to draw a line decreased from 2.6 ms per line to 376 µS.

 

In the next blog, we'll try to bring the 360 µS pixel data transmit further down by using buffered SPI.

 

The Series
0 - Buffers and Parallel Data Lines
1a - Buffers and DMA
1b - SPI without Buffers
2 - SPI with Buffers
3a - SPI with DMA
3b - SPI with DMA works
4a - SPI Master with DMA and Parallel Data Lines
Hercules microcontrollers, DMA and Memory Cache
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 7 years ago in reply to DAB +4
    Here's the test set-up: A Hercules RM46 LaunchPad. The RM46 is part of TI's Hercules family. This one is specialised in industrial and medical applications. Loads of safety features on that controller…
  • Jan Cumps
    Jan Cumps over 7 years ago +4
    Sneak preview: This isn't a full functioning implementation yet, but by tweaking some SPI registers in debug mode, I managed to push 128 16-bit values in one go: 82 µs for a full line. Compared to non…
  • Jan Cumps
    Jan Cumps over 7 years ago +4
    Issue resolved in less than an hour. It was pebkac. Datasheet says that we can have 128 values in our buffer. I was trying to send 128 at a time and that failed. The reason for this: I'm using 3 transfer…
  • Jan Cumps
    Jan Cumps over 7 years ago

    Issue resolved in less than an hour.

    It was pebkac. Datasheet says that we can have 128 values in our buffer.

    I was trying to send 128 at a time and that failed.

    The reason for this:

    image

    I'm using 3 transfer groups.

    1 to send single 8-bit values (for LCD commands)

    1 to send single 16-bit values (for single pixel drawing)

    1 to send buffered 16-bit values (for multiple pixels at the same time)

     

    I didn't get that the buffer is shared between the groups. So I can't use all 128 buffer positions in group2, because 2 of the 128 available buffer positions were already taken in group0 and group1.

    I restructured my code to reduce the buffer size, and all works (FAST image ).

    I'll prepare a blog tomorrow.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 7 years ago in reply to Jan Cumps

    I logged a help request at the TI E2E forum.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 7 years ago

    I was hoping that the next step would be easy: switching to buffered SPI.

    I've used it before for small buffers.

     

    I'm now trying to develop a design that buffers a full line of 128 16 bit values.

    It doesn't work as expected (unless - as shown above - I hack registers at debug time) , so I'll have to spend some more time learning Hercules buffered SPI.

     

    I'll first try to replicate a test bed I made a year ago that works with 64 16-bit values.

    That's the consequence of working with the Hercules ARM family. Extremely powerful and safe; Equally extremely complex to work with. The good side of that is that when it works, you are a subject expert forever image .

    Hang on...

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 7 years ago in reply to Jan Cumps

    Nice post!! Also that analyzer has got me out of a few holes over the years : ) A nice design that "just works"..

    LOL @ ft*i. Thinking of creating a through-hole PCB  (open source of course) design for MCP2221, I've been using the

    stripboard prototype version for months now, reliable part from Microchip. Since it has a built-in ADC, that could be a value-add,

    e.g. use it for testing what the applied voltage is, since not all hobbyists initially have a multimeter.

    Open to ideas/suggestions though on any features you'd like to see in such a through-hole project, form factor, etc.

    Another option is to turn the spare GPIO pins into an MSP430 programmer. Kind of like a beginners swiss army knife.

    Just need to keep the parts count low.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 7 years ago

    Sneak preview:

     

    This isn't a full functioning implementation yet, but by tweaking some SPI registers in debug mode, I managed to push 128 16-bit values in one go:

    image

     

    82 µs for a full line. Compared to non-buffered mode where it took 360 µs, we have between 4-5 times faster throughput.

    This is a prediction of what the non-DMA buffered mode will give us at 27.5 Mbit/sec, wih a single data line.

     

    My calculator says that 16 bits * 128 = 2048 bits.

    It took me 82 µs to move them.

    2048 / 0.000082 = 24975609.75609756.

     

    The theoretical speed was 27.5 megabits.

    I moved 24.975610 megabits

    Efficiency: 90.82%

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube