Jump to content
43oh

XIN/XOUT as digital outputs


Recommended Posts

Hello all.

 

According to Hardware scheme on GitHub wiki both XIN and XOUT can be used for digitalRead/digitalWrite however I haven't had any success with it. How I can use this pins for digital output?

 

Sorry if I missed the answer on this forum (but I honestly tried to find the answer before posting my question)

Link to post
Share on other sites

Not, I'm not able to use it:

LED.cpp:18:83: error: 'P2_6' was not declared in this scope

 

Here is the part of the code where initialization happens:

byte seg = 0;
byte segA = 11;
byte segB = 7;
byte segC = 4;
byte segD = 2;
byte segE = 1;
byte segF = 10;
byte segG = 5;
byte segDP = 3;

byte digit1 = 12;
byte digit2 = 9;
byte digit3 = 8;
byte digit4 = 6;
byte digits_available = 4; // Amount of available digits on display

//                    1,    2,    3,    4,    5,    6,    7,    8,    9,    10,   11,   12 
byte pin_map[] = {-1, P2_4, P2_5, P1_6, P1_7, P1_4, P1_3, P1_5, P2_0, P2_1, P2_2, P2_6, P2_3};
byte char_map[128]; // Fragmented set of first 128 characters of ASCII table.
byte seg_map[] = {segA, segB, segC, segD, segE, segF, segG, segDP};
byte digits_map[4] = {digit1, digit2, digit3, digit4};


void setup() {
 P2SEL &= ~(BIT6|BIT7);  
 char_map['0'] = B11111100;
 char_map['1'] = B01100000;
 char_map['2'] = B11011010;
 char_map['3'] = B11110010;
 char_map['4'] = B01100110;
 char_map['5'] = B10110110;
 char_map['6'] = B10111110;
 char_map['7'] = B11100000;
 char_map['8'] = B11111110;
 char_map['9'] = B11110110;

 char_map['H'] = B01101110;
 char_map['L'] = B00011100;
 char_map['E'] = B10011110;
 char_map['R'] = B11101110;


 Serial.begin(9600);
 int i;

 for (i = 1; i < sizeof(pin_map); i++) {
   pinMode(pin_map[i], OUTPUT);
 }
}

Link to post
Share on other sites

Yeah, sorry. P2_6 would normally come from pins_energia.h but I can see that is defined as NOT_A_PIN. NOT_A_PIN ignores any attempts to change its mode or value.

 

You should be able to use this to code make them both output in setup()

 

P2SEL &= ~(BIT6|BIT7);
P2DIR |= (BIT6|BIT7);

When you want to turn them on and off:

...
P2OUT |= BIT6; // to turn on
P2OUT &= ~BIT6; // to turn off
...
...
P2OUT |= BIT7; // to turn on
P2OUT &= ~BIT7; // to turn off
...

Link to post
Share on other sites

No, no luck yet :(

 

that is modified chunk of my code

 

byte pin_map[] = {-1, P2_4, P2_5, P1_6, P1_7, P1_4, P1_3, P1_5, P2_0, P2_1, P2_2, 19, P2_3};
byte char_map[128]; // Fragmented set of first 128 characters of ASCII table.
byte seg_map[] = {segA, segB, segC, segD, segE, segF, segG, segDP};
byte digits_map[4] = {digit1, digit2, digit3, digit4};


void setup() {
 P2SEL &= ~(BIT6|BIT7);
 P2DIR |= (BIT6|BIT7);
 P2OUT |= BIT7;
 P2OUT |= BIT6;

 char_map['0'] = B11111100;
 char_map['1'] = B01100000;
 char_map['2'] = B11011010;
 char_map['3'] = B11110010;
 char_map['4'] = B01100110;
 char_map['5'] = B10110110;
 char_map['6'] = B10111110;
 char_map['7'] = B11100000;
 char_map['8'] = B11111110;
 char_map['9'] = B11110110;

 char_map['H'] = B01101110;
 char_map['L'] = B00011100;
 char_map['E'] = B10011110;
 char_map['R'] = B11101110;


 Serial.begin(9600);
 int i;

 for (i = 1; i < sizeof(pin_map); i++) {
   pinMode(pin_map[i], OUTPUT);
 }
}

Link to post
Share on other sites

Sure.

 

Here is the code:

pastebin dt com slsh BGPC7iBk

 

Schematic is very simple, basically it's 4 digits 7 segments led indicator connected straight to outputs of LaunchPad (can make a photo if you want :)).

 

I'm trying to port a part of my bigger Arduino project. LED indicator should be connected to 12 outputs of LaunchPad and I still need serial port and one button available. I know that there is some tricks to power it from smaller amount of legs but I need it to work dead simple at the moment, without extra chips, etc.

Link to post
Share on other sites

Table 21 and Table 22 in the 2553 datasheet show Pin Functions shows P2SEL as low for GPIO which is what you want.

 

P2SEL &= ~(BIT6|BIT7);

The above will put it those pins into XIN/XOUT mode which is not what you want.

Looking at the code on http://pastebin.com/BGPC7iBk you call digitalWrite for pin 19 (P2.6). Unfortunately this pin is not in the pin map and thus it will not work.

 

The fix:

In the file hardware/msp430/variants/launchpad/pins_energia.h change digital_pin_to_port[] and digital_pin_to_bit_mask[] to look like below. I don't have a Launchpad handy right now so can't test it but am pretty sure that this change will do the trick.

 

Will fix it and make sure that it will go into the next release.

 

const uint8_t digital_pin_to_port[] = { 
       NOT_A_PIN, /* dummy */
       NOT_A_PIN, /* 1 */
       P1, /* 2 */
       P1, /* 3 */
       P1, /* 4 */
       P1, /* 5 */
       P1, /* 6 */
       P1, /* 7 */
       P2, /* 8 */
       P2, /* 9 */
       P2, /* 10 */
       P2, /* 11 */
       P2, /* 12 */
       P2, /* 13 */
       P1, /* 14 */
       P1, /* 15 */
       NOT_A_PIN, /* 16 */
       NOT_A_PIN, /* 17 */
       P2, /* 18 */
       P2, /* 19 */
       NOT_A_PIN, /* 20 */
};

const uint8_t digital_pin_to_bit_mask[] = {
       NOT_A_PIN, /* 0,  pin count starts at 1 */
       NOT_A_PIN, /* 1,  VCC */
       BV(0),     /* 2,  port P1.0 */
       BV(1),     /* 3,  port P1.1 */
       BV(2),     /* 4,  port P1.2 */
       BV(3),     /* 5,  port P1.3*/
       BV(4),     /* 6,  port P1.4 */
       BV(5),     /* 7,  port P1.5 */
       BV(0),     /* 8,  port P2.0 */
       BV(1),     /* 9,  port P2.1 */
       BV(2),     /* 10, port P2.2 */
       BV(3),     /* 11, port P2.3 */
       BV(4),     /* 12, port P2.4 */
       BV(5),     /* 13, port P2.5 */
       BV(6),     /* 14, port P1.6 */
       BV(7),     /* 15, port P1.7 */
       NOT_A_PIN, /* 16, RST */
       NOT_A_PIN, /* 17, TEST */
       BV(7),     /* 18, XOUT */
       BV(6),     /* 19, XIN */
       NOT_A_PIN, /* 20, GND */
};

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...