Skip to content

Commit da33244

Browse files
committed
Merge pull request energia#64 from energia/issue_64
digitalWrite leaves pin in PWM mode if PWM was previously enabled with analogWrite
2 parents 4443466 + 15d291c commit da33244

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

hardware/msp430/cores/msp430/wiring_digital.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ void digitalWrite(uint8_t pin, uint8_t val)
7979
uint8_t bit = digitalPinToBitMask(pin);
8080
uint8_t port = digitalPinToPort(pin);
8181
volatile uint16_t *out;
82+
volatile uint16_t *sel;
8283

8384
if (port == NOT_A_PORT) return;
8485

86+
/*
87+
* Clear bit in PxSEL register to select GPIO function. Other functions like analogWrite(...)
88+
* will set this bit so need to clear it.
89+
*/
90+
sel = portSelRegister(port); /* get the port function select register address */
91+
*sel &= ~bit; /* clear bit in pin function select register */
92+
8593
out = portOutputRegister(port);
8694

8795
if (val == LOW) {

0 commit comments

Comments
 (0)