hary 0 Posted June 17, 2014 Share Posted June 17, 2014 Hi Doing my first step with my LP I can't get the instruction : bitSet(P1OUT,P1_0); working. It should be equivalent to "digitalWrite (P1_0, 1);" but the previous instruction don't light up the led ! Do I do something wrong ? The same happen with "P1OUT |= (1<<P1_0)". I can't get the led on ! Quote Link to post Share on other sites
chicken 630 Posted June 17, 2014 Share Posted June 17, 2014 In Energia, P1_0 is a placeholder for the pin number on the headers (e.g. P1_0 = 2 on the MSP-EXP430G2 LaunchPad). DigitalWrite translates that number to the actual port and bit. If you want to directly work with P1OUT, use the bit number of the desired pin. E.g. bitSet(P1_0,0) or P1OUT |= BV(0)). Quote Link to post Share on other sites
hary 0 Posted June 17, 2014 Author Share Posted June 17, 2014 Many thanks for the help ! Quote Link to post Share on other sites
roadrunner84 466 Posted June 25, 2014 Share Posted June 25, 2014 I think the main difference is in the fact that digitalWrite will set the pin to output mode, while bitSet does no such thing. If you'd like to use bitSet, be sure that during setup or directly before setting the big high, you make the pin an output by either calling digitalWrite once, or call bitSet(P1DIR,P1_0); Using P1OUT |= (1<<P1_0); is a very bad idea, since P1_0 is not the bit within the byte but the pin within the device, In such a case, batter use P1OUT |= 1 << 0; (where 0 is the bit number) Quote Link to post Share on other sites
chicken 630 Posted June 25, 2014 Share Posted June 25, 2014 I think the main difference is in the fact that digitalWrite will set the pin to output mode, while bitSet does no such thing. If you'd like to use bitSet, be sure that during setup or directly before setting the big high, you make the pin an output by either calling digitalWrite once, or call bitSet(P1DIR,P1_0); Umm, while digitalWrite might do that under the hoods, pinMode is what should be used to set a pin as output. Quote Link to post Share on other sites
roadrunner84 466 Posted June 26, 2014 Share Posted June 26, 2014 Umm, while digitalWrite might do that under the hoods, pinMode is what should be used to set a pin as output. Depends on your frame of usage, either use the pinMode/digitalWrite etc calls from the Energia API, or use the GPIO registers P1OUT/P1REN/P1DIR etc from the msp430. It is awkward to use pinMode and then use P1OUT, but it's fine to use pinMode together with digitalWrite, as is using P1DIR together with P1OUT. Quote Link to post Share on other sites
zlalanne 37 Posted June 26, 2014 Share Posted June 26, 2014 If you are working with a BoosterPack and want the code compatible across LaunchPads you should stick to just using the pin number in your function calls. That way if someone wants to port it to another LaunchPad all the pin numbers are the same even though the underlying pins are different. This will work across all launchpads: pinMode(1, OUTPUT) digitalWrite(1, HIGH) This will always use P1_0, which may be in a different place on each launchpad: pinMode(P1_0, OUTPUT) digitalWrite(P1_0, HIGH) Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.