element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum The RP2040 PIO Module is Pretty Nifty
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 16 replies
  • Subscribers 661 subscribers
  • Views 10671 views
  • Users 0 members are here
Related

The RP2040 PIO Module is Pretty Nifty

scottiebabe
scottiebabe over 4 years ago

Soft 404

  • Sign in to reply
  • Cancel
Parents
  • pablolien
    pablolien over 3 years ago

    How do you define rp2.StateMachine in micropython?  When I use out_base = (Pin(10), Pin(11....)) mpy reply with "ValueError: expecting a Pin", I suppose it not sopport more than 1 pin. 

    Thx.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to pablolien

    .

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • pablolien
    pablolien over 3 years ago in reply to scottiebabe

    Thank you for the reply.  

    Are you try the some code with "out_shiftdir=PIO.SHIFT_LEFT" sometime? 

    I found that SHIFT_RIGHT works fine, but SHIFT_LEFT not.  Is it a problem of micropython or RP2040 limitation?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • pablolien
    pablolien over 3 years ago in reply to scottiebabe

    Thank you for the reply.  

    Are you try the some code with "out_shiftdir=PIO.SHIFT_LEFT" sometime? 

    I found that SHIFT_RIGHT works fine, but SHIFT_LEFT not.  Is it a problem of micropython or RP2040 limitation?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
  • scottiebabe
    scottiebabe over 3 years ago in reply to pablolien

    .

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • pablolien
    pablolien over 3 years ago in reply to scottiebabe

    I'm programming a 16bits to 4bits comm protocol...  4 bits of data, a DEN (data enable) and a CS (chip select. )  It's just for check RP2040's capability. 

    import array, time
    from machine import Pin
    import rp2

    #protocolo de conversion de 16bit a 4bit (en 4 tramos con una salida de DEN (data enable) franco bajada
    # y EN en positivo.)
    @rp2.asm_pio(out_init = [rp2.PIO.OUT_LOW] * 4,
                 sideset_init = [rp2.PIO.OUT_HIGH] * 2,
                 out_shiftdir = rp2.PIO.SHIFT_LEFT,
                 autopull = True, pull_thresh = 16)
    def pioNiple():
       set(x, 3)      .side(0b01)    
       label("loop")
       out(pins, 4)   .side(0b11)
       nop()          .side(0b10)          
       jmp(x_dec, "loop") .side(0b11)
       nop()          .side(0b01)    
       
    sm = rp2.StateMachine(0, pioNiple, freq=2000,
                          sideset_base = Pin(14),
                          out_base = Pin(10))

    # Start the StateMachine, it will wait for data on its FIFO.
    sm.active(1)
    sm.put(0xFFAA)
    sm.put(0xAA01)
    This is when I use shift_left  Channel 0..3 bit 0..3  channel 4 is DEN and channel 5 is CS. 
    shiftleft
    When I use Shift_right, It works perfectly. 
    shift_right
    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to pablolien

    .

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • pablolien
    pablolien over 3 years ago in reply to scottiebabe

    YES!!!  YOU'RE RIGHT!!!  

    It works fine if I make shift 16bit before using sm.put.

    I can avoid having to do shift in sm.put change pio.asm code for 32bit instead of 16bit,

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • pablolien
    pablolien over 3 years ago in reply to pablolien

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • pablolien
    pablolien over 3 years ago in reply to pablolien

    I'm imagine convert a rp2040 to a fast 6502 ???  Slight smile

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • 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 © 2025 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