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
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
microbit Forum Problem with ISP on micro:bit
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 13 replies
  • Subscribers 50 subscribers
  • Views 3599 views
  • Users 0 members are here
  • shift register
  • micro:bit
  • digital write
  • python
  • bbc micro:bit
  • spi
  • tempus fugit
  • mu editor
  • chip select
  • protocol
  • spi not working
Related

Problem with ISP on micro:bit

balearicdynamics
balearicdynamics over 7 years ago

I have a strange issue with the micro:bit that I have no idea by what it can depends. Maybe also a behavioural detail I have not considered and I am expecting something that it is normal does not happens.

 

The scenario

For more detail on how the project is designed take a look to the blog posts on Tempus fugit...

 

Tempus Fugit... Part 1: 1978 a.d.  project intro

Tempus Fugit... Part 2: 2018 a.d. the components and the logic of the project

Tempus Fugit... Part 3: micro:bit Interfacing 5V Logic the first issue: interfacing 3.3 logic signals from micro:bit to 5V logic on IC. Tested and solved

Tempus Fugit... Part 4: micro:bit 5V SPI adopting the solution discussed in the previous blog post to my use case: 7-segments LED controller via SPI protocol.

 

The problem

Hardware seems working properly; with simple programs to control the pins involved by the SPI protocol (13, 14, 15 on the micro:bit) and testing with the oscilloscope bon both sides 3.3 V (output connector from the micro:bit) and 5V (input connection to the IC) these works perfectly and there are no problems. Then, I tried to implement in Python using MU the SPI protocol and on the same pins controlling with the oscilloscope nothing happens. To do this I have used the Python library to control the specific IC but none at all. I am not interested in this moment to see the display working. What I just need to understand is what can be the issue that is blocking the SPI protocol to work correctly, also when the test program runs on on the micro:bit without the controlled circuit connected to avoid interferences. The same behaviour happens on a second micro:bit board, while the digital output setting of the pins with the test program continue working; I can suppose that there is not any hardware problem.

 

Any suggestion and idea is more than welcome image

 

Enrico

  • Sign in to reply
  • Cancel

Top Replies

  • jc2048
    jc2048 over 7 years ago +4
    This code works with the Python Editor on their website # Add your Python code here. E.g. from microbit import * buf = bytearray(1) spi.init() while True: buf[0]=0xa4 spi.write(buf) sleep(20) these…
  • stevesmythe
    stevesmythe over 7 years ago +4
    Hi Enrico I have used SPI with the micro:bit a couple of times - with two different 7-seg displays. I can't see from your project what SPI controller IC you are trying to control. If you could post the…
  • balearicdynamics
    balearicdynamics over 7 years ago in reply to stevesmythe +4
    Hello Steve, Thank you for your support. Now it wkrkw and tomktrow I will setup the software. Enrico
Parents
  • stevesmythe
    stevesmythe over 7 years ago

    Hi Enrico

     

    I have used SPI with the micro:bit a couple of times - with two different 7-seg displays. I can't see from your project what SPI controller IC you are trying to control. If you could post the datasheet for that component it would be helpful.  In addition to the SPI controls, there is usually another pin called chip select or CS on the controller IC to "latch" the data to the display. To send anything to the display you need to take the chip select pin (P0) low, then send the data, then take the chip select pin high again.Here is my micropython code for a MAX7219 controller.

     

     

    from microbit import *

    # setup SPI

    spi.init(baudrate=1000000, bits=8, mode=0, sclk=pin13, mosi=pin15, miso=pin14)

    # initialisation code

     

    pin0.write_digital(0)

    spi.write(b'\x0f\x00')  # enable normal mode and disable test mode

    pin0.write_digital(1) # latch data

    sleep(300)

     

    With best wishes

     

    Steve

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • stevesmythe
    stevesmythe over 7 years ago

    Hi Enrico

     

    I have used SPI with the micro:bit a couple of times - with two different 7-seg displays. I can't see from your project what SPI controller IC you are trying to control. If you could post the datasheet for that component it would be helpful.  In addition to the SPI controls, there is usually another pin called chip select or CS on the controller IC to "latch" the data to the display. To send anything to the display you need to take the chip select pin (P0) low, then send the data, then take the chip select pin high again.Here is my micropython code for a MAX7219 controller.

     

     

    from microbit import *

    # setup SPI

    spi.init(baudrate=1000000, bits=8, mode=0, sclk=pin13, mosi=pin15, miso=pin14)

    # initialisation code

     

    pin0.write_digital(0)

    spi.write(b'\x0f\x00')  # enable normal mode and disable test mode

    pin0.write_digital(1) # latch data

    sleep(300)

     

    With best wishes

     

    Steve

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
Children
  • balearicdynamics
    balearicdynamics over 7 years ago in reply to stevesmythe

    Hello Steve,

    thank you very much for your suggestions. I will try immediately. You mention pin0. As far as I know, there is no difference between pin0 or any other digital I/O pin or for some reason that I don't know it is absolutely necessary to use this pin? The reason is that I will use pin0 to generate audio frequency and as far as I know only pin0 can do this easily in the micro:bit.

     

    I am aware of the CS pin (number 12 on the 7219) asI am using the same IC. Now I will test your suggested program and see what happens with pin0. I will update you shortly.

     

    Enrico

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • stevesmythe
    stevesmythe over 7 years ago in reply to balearicdynamics

    Sorry, I chose P0 at random as the CS pin (you can use any unused pin). In your case, just modify my code but connect CS  on the 7219 to (say) P12 on the micro:bit and change my code to:

     

    pin12.write_digital(0) etc etc.

     

    The MAX7219 is quite complicated to get fully working (it has many "modes") but my code snippet will get "test mode" working easily. I have a blog post here that goes into more detail about using this controller with the micro:bit.

     

    Good luck.

     

    Steve

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 7 years ago in reply to stevesmythe

    Hello Steve,

     

    Thank you for your support. Now it wkrkw and tomktrow I will setup the software. imageimage

     

    Enrico

    image

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • stevesmythe
    stevesmythe over 7 years ago in reply to balearicdynamics

    Hi Enrico

     

    That's great news! "Test mode" looks good image  I look forward to following your project to completion.

     

    With best wishes

     

    Steve

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 7 years ago in reply to stevesmythe

    Hi Steve,

     

    thank you again. I took a look at the link on your blog and it seems very complete and detailed, I think it is very useful for my project.

     

    Cheers, Enrico

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • stevesmythe
    stevesmythe over 7 years ago in reply to balearicdynamics

    Let me know if you have any problems. I should warn you that loading my whole python program will take you very close to the memory limit of the micro:bit, so you should just take the bits you need.

     

    In particular, if you only need numerals, you can delete a lot of the "dictionary" (e.g. lines 54 to 105). Also, once you have it working, you won't need "test mode" any more (lines 5 to 8). In normal use you won't need lines 10 to 16 (starting "# zero-out all registers"). This function allocates a large array which uses a lot of memory. Unless you delete these parts, you probably won't have enough memory for your other code.

     

    Obviously you'll have to change the "scan limit" register (0x0b) to 0x03 (4 columns) instead of 0x07 (8 columns).

     

    Otherwise I think you should be OK. Getting that display working fully took me a lot of effort so I hope I've saved you some of that!

     

    With best wishes

     

    Steve

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 7 years ago in reply to stevesmythe

    Hello Steve, I think this is a very useful thread ...

    Thank you for the suggestion, I was just having in mind to extract just the essential parts from your job, due the supposed problems of memory. Your details are useful to avoid to delete needed parts and vice-versa.

     

    My 2 cent suggestion instead is on how Python import works. I see that a common practice is always using from micro:bit import * but in this way you include ALL the available classes. Most of them are totally useless in many situations so a lot of memory can be saved importing only the right library(es) For example, if you only need SPI it is not the worth to import everything else but only the following :

     

    from microbit import SPI PIN0 PIN13 PIN14 PIN15

     

    As far as I know this can save a lot of memory.

    I am not an expert in mycroPython so at the moment what I am investigating is the exact name of the microbit libraries (to choose what import and what don't) and how much memory the parts occupy.

     

    Enrico

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • stevesmythe
    stevesmythe over 7 years ago in reply to balearicdynamics

    You are quite right. I find it easier to just import * when I am developing a program. Then I should optimise it later by only importing the modules that I need, once I know which pins or other built-in modules that I am using (e.g. SPI, I2C). However, I usually forget to do this! By default Mu also downloads comments  and whitespace to the micro:bit (which takes up more memory) but you can turn this off  ("minify") in the latest version of Mu. See here.

    • Cancel
    • Vote Up +2 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