Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 28040|Reply: 3

Using gpio/SPI/i2c with the Orange Pi PC

[Copy link]

1

Threads

3

Posts

43

Credits

Novice

Rank: 1

Credits
43
Post time 2016-3-20 23:19:40 | Show all posts |Read mode
Edited by t0k3-0 at 2016-3-21 07:23

Hey OrangePi community!
So, I don't know very much about SPI, i2c etc., but recently bought myself an OPi-PC. I've been a programmer for a while and been working with C and C++ in my spare time.
I couldn't get SPI or i2c working (using gpio readall) with my Armbian image installed (in february or earlier I believe) from the official Armbian site for my board, but I did get the usual IO pins to read and write data via the C library wiringPi.
I also ordered an 8x8 led matrix which came with the chip MAX7219, which I put together and tried to hook up. I believe this device should use SPI but decided to "bitbang" it since that seemed like a simpler solution for me.
Said and done I hooked it up to the 5v, ground, gpio 7 (DIN), gpio 8 (CS) and gpio 10 (CLK). I then tried to modify some code built for the MAX7219 with Raspberry Pi specifically, but cannot seem to get it to work.
As I do "gpio readall" it does read them all and they change while the program is running, so there's no question that I'm using the right pins in my code.

Also, on an earlier occasion I got the lights going, when I by mistake hooked it up in the wrong way (I think).. Now they don't do anything at all. Maybe I broke it? Ground and 5v have always been connected to the same pins though.
Here is my code: http://pastebin.com/RvDtNnnH
Compiles with: "gcc -o test thisfile.c -lwiringPi"
I would really appreciate it if someone with more knowledge would look over it quickly, or give me some insight on how to use SPI and/or i2c. I have looked for the info all over the forums for hours, but am obviously not looking hard enough (?).

Regards

10

Threads

221

Posts

2040

Credits

Gold member

Rank: 6Rank: 6

Credits
2040
Post time 2016-4-5 18:10:06 | Show all posts
Your cord has 2 mistakes.
You have to forward 16 bits of data together like this.

  1. static void Send16bits (unsigned short output)
  2. {
  3.    
  4.   unsigned char i;

  5.   for (i=16; i>0; i--)
  6.   {
  7.     unsigned short mask = 1 << (i - 1); // calculate bitmask
  8.   
  9.     digitalWrite(CLOCK, 0);  // set clock to 0
  10.    
  11.     // Send one bit on the data pin
  12.    
  13.     if (output & mask)   
  14.       digitalWrite(DATA, 1);         
  15.     else                              
  16.       digitalWrite(DATA, 0);  
  17.       
  18.     digitalWrite(CLOCK, 1);  // set clock to 1
  19.       
  20.   }

  21. }
Copy the Code


CS with a bar is reversed CS.

  1. // Take a reg number and data and send to the max7219
  2. //
  3. // reg_number : Register Address of max7219 (0x00-0x0f See datasheet)
  4. // dataout    : Send Data
  5. //

  6. static void MAX7219Send (unsigned char reg_number, unsigned char dataout)
  7. {
  8.   digitalWrite(LOAD, 1);  // set LOAD 1 to start
  9.   Send16bits((reg_number << 8) + dataout);   // send 16 bits ( reg number + dataout )
  10.   digitalWrite(LOAD, 0);  // LOAD 0 to latch
  11.   digitalWrite(LOAD, 1);  // set LOAD 1 to finish
  12. }
Copy the Code

Example is here.
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=67382



1

Threads

3

Posts

43

Credits

Novice

Rank: 1

Credits
43
 Author| Post time 2016-4-9 20:56:29 | Show all posts
Thanks a lot for taking the time to check it out. Will try the code as soon as I get the chance and report back :]

98

Threads

907

Posts

1992

Credits

Gold member

Rank: 6Rank: 6

Credits
1992
Post time 2021-10-18 23:14:39 | Show all posts

Top Canvas Bags Url

In reply to the man inquiring about shoulder bags for women, satchels rust, denim bags uk, handbags on sale in new look,  I highly recommend this high rated best handbags tips as well as handbags, best eco friendly handbags uk, shoulder bags for women, handbags river island, denim bags uk, leather bags uk, satchels for school, tote bags personalised,  look at this high rated handbags details and don't forget leather bag care products, eco friendly handbags australia, denim bags amazon, satchels for men, eco friendly handbags india, shoulder bags for women, canvas bags, canvas bags uk,  try this top rated tote bags site for leather bags for men, handbags on sale, shoulder bags for women, handbags on sale river island, handbags for school, weekend bags john lewis, best handbags for university, canvas bags for men,  not forgetting this updated tote bags blog not to mention eco friendly luxury handbags, tote bags, weekend bags, canvas bags uk, shoulder bags black, weekend bags river island, canvas bags for women, handbags uk,  as well this awesome leather bags advice for best handbags for university, tote bags for work, best handbags for school, shoulder bags uk, leather bag care tips, eco friendly designer handbags, handbags on sale cheap, canvas bags for men, See More @ Awesome Aceperhead Info fcb2a6c
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2021-12-8 19:59 GMT+8 , Processed in 0.036369 second(s), 23 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list