SPI code conversion
bnikkel
Posts: 104
in Propeller 1
Hello everyone, I am using a shift register (74HC595) and I have written some code that is working perfect on the BS2, but I cant seem to figure out how to do the same on the propeller in C. the BS2 code shifts out 8 bits each being its own variable so I can change any one of them at any time without changing the rest.
Out_595:
SHIFTOUT SerData, Clock, MSBFIRST, [op7\1, op6\1, op5\1, op4\1, op3\1, op2\1, op1\1, op0\1]
PULSOUT Latch, 5
RETURN
I am able to communicate with the 595 on the propeller perfectly with the code below. but I have been unable to make it so I can simply change the value of variables like the code above. any help is greatly appreciated thanks.
shift_out(21, 22, MSBFIRST, 8, 0b00000000);
Out_595:
SHIFTOUT SerData, Clock, MSBFIRST, [op7\1, op6\1, op5\1, op4\1, op3\1, op2\1, op1\1, op0\1]
PULSOUT Latch, 5
RETURN
I am able to communicate with the 595 on the propeller perfectly with the code below. but I have been unable to make it so I can simply change the value of variables like the code above. any help is greatly appreciated thanks.
shift_out(21, 22, MSBFIRST, 8, 0b00000000);
Comments
But here ya go:
Also, you forgot closing right parentheses after both of your for loops before the left curly brackets.
I like the C++ version because of the bool type. Makes the code a bit shorter. But he asked for C, so I thought it would be nice to include both.
Thanks for noticing. I'll get that fixed.
Certainly understandable. When we have folks talking about running JavaScript on the Propeller, and using 64-bit floats for everything, I would say a little array for some bits isn't too big of a deal :P. Simply be aware of the performance issues and, if you run into problems (speed or code size), you'll know one good place to look for optimization opportunities.
just wanted to update this. i revisited an old problem and have figured out a solution to it. being able to update variables independently and then shift_out to the 595. seems easy now but 5 years ago it was beyond me.
`/*
74HC595 com test
*/
include "simpletools.h" // Include simpletools lib
long newvalue;
int a = 1;//1;
int b = 0;//2;
int c = 0;//4;
int d = 0;//8;
int e = 0;//16;
int f = 0;//32;
int g = 0;//64;
int h = 0;//128;
int i = 1;//256
int j = 1;//512;
int k = 0;//1024;
int l = 0;//2048;
int m = 0;//4096;
int n = 0;//8192;
int o = 0;//16384;
int p = 1;//32768;
int main() // Main function
{
shift_out(0, 1, LSBFIRST, 16, newvalue); // Value for MCTL register
pulse_out(6, 1);
pause(500);
}`
Thanks for the update. You answered my question.