This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I have much code written for other compilers and I want to use the same code for the MSP430F5632. I want to use this style code DisplayRESET = 0; where DisplayRESET is a single pin. Here is the struct and #defines I have:
struct BitMapping
{
unsigned
Bit0:1,
Bit1:1,
Bit2:1,
Bit3:1,
Bit4:1,
Bit5:1,
Bit6:1,
Bit7:1;
}CHR;
#define Port1_2Base 0x200
#define Port2OUTCHAR ( * (char *)Port1_2Base + 0x03)
#define Port2OUT ( * (struct BitMapping *)Port1_2Base + 0x03)
#define Port5_6Base 0x240
#define Port5OUT ( * (struct BitMapping *)Port5_6Base + 0x02)
#define Port6IN ( * (struct BitMapping *)Port5_6Base + 0x01)
#define Port6OUT ( * (struct BitMapping *)Port5_6Base + 0x03)
#define Port7_8Base 0x260
#define Port7IN ( * (struct BitMapping *)Port7_8Base + 0x00)
#define Port7OUT ( * (struct BitMapping *)Port7_8Base + 0x02)
#define DisplayCD Port6OUT.Bit6
#define DisplayCE Port7OUT.Bit7
#define DisplayWR Port7OUT.Bit6
#define DisplayData Port2OUT.CHR
#define DisplayRD Port6OUT.Bit7
#define DisplayRESET Port5OUT.Bit6
When I compile, everywhere I use a display pin like:
DisplayCD = 0;
I get:
Description Resource Path Location Type
#42 expression must have arithmetic or pointer type DisplayRoutines.c /HRX MSP Ccode/MSP HRX CCODE line 89 C/C++ Problem
I have not found any examples of pins being used like this. It's all:
DisplayCD |= BIT6;
or
DisplayCD &=~BIT6;
What do I need to do to use:
DisplayCD = 0;
Hi David,
This is in interesting question. I'm unsure if there is an easy way to do this on MSP430. The reason is a bit set/clear requires a readback of the GPIO PxOUT register. Hence the need for "|=" (which is just x = x | y). As far as I know there isn't a single C operation that can do this.
The BitMapping struct is neat but I've never seen the ":1" notation before. Can you point me at a reference that describes how this works?
What compiler/MCU have you been able to use this software paradigm with?
Regards,
Evan
FOUND IT!!!
Compiler does not like calculating addresses. Just by chance I tried:
#define Port5OUT ( * (struct BitMapping *)0x242)
#define Port6IN ( * (struct BitMapping *)0x241)
#define Port6OUT ( * (struct BitMapping *)0x243)
and my errors went away. Somehow calculating the address works in msp430f5632.h which is part of the compiler.
Hi David,
I was able to make it work with a couple modifications to your original code:
#include <msp430.h> struct __attribute__((__packed__)) BitMapping { unsigned Bit0:1, Bit1:1, Bit2:1, Bit3:1, Bit4:1, Bit5:1, Bit6:1, Bit7:1; }CHR; #define Port1_2Base 0x200 #define Port2OUT ( (struct BitMapping *)Port1_2Base + 0x03) int main(void) { WDTCTL = WDTPW+WDTHOLD; // Stop WDT P2DIR |= 0xFF; while (1) { Port2OUT->Bit5 = 1; __delay_cycles(1000); Port2OUT->Bit5 = 0; __delay_cycles(1000); } }
The key changes:
I was able to see the pin toggel in my example :) Happy coding.
Evan
**Attention** This is a public forum