Part Number: MSP430FR6989
Hi,
For a project I'm working with 2 MSP430FR6989, I need them to communicate to each other in a very specific way (No I cannot use I2C, SPI or other protocols like that). I need to use the GPIO ports to give through an address (ports 4, 8 and 9 for me), and Port 2 gives through data. The address is then "converted" to a pointer at which the data is stored.
However, It seems I am not able to read the in the PxIN registers and concatenate the to the address. I cannot even read out the entire Port2 and put it in the variable. I checked that the databits are coming through via the registers (in CCS debugger), and they do. What seems to be the problem here?
Code:
#include <msp430.h>
#include "ram_module.h"
/**
* main.c
*/
int main(void)
{
PM5CTL0 &= ~LOCKLPM5;
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
//declare all the pins
//Control Ports
P3DIR |= 0b00000000; // third port is CSN port, this is READ ONLY
P3IE |= 0b00000111;
P3IES |= 0x03 ; // from high to low on the first two pins
P3IFG &= ~0x03 ; // clear the flags
__bis_SR_register(GIE); // enable interrupts
//Address Ports (Port 1: 5, Port 8: 4, Port 9: 7), READ ONLY
P1DIR |= 0b00000000;
P8DIR |= 0b00000000;
P9DIR |= 0b00000000;
//Data Port
P2SEL0 &= 0x00;
P2DIR |= 0x00;
//For debugging
while(1){
__no_operation();
}
return 0;
}
/*
* Each port has only one vector and only one ISR can be written.
* To distinguish between different interrupt sources for one interrupt vector,
* in this case the different port pins, you'll have to check the IFG bits inside the ISR.
*/
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT3_VECTOR
__interrupt void Port_3(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT3_VECTOR))) Port_3 (void)
#else
#error Compiler not supported!
#endif
{
uint16_t volatile * const address = (uint16_t *) getAddress();
//uint16_t* data = NULL;
//data = address;
if(P3IFG&BIT0){
//P1OUT^=BIT0; data is written to this MPC
*address = P2IN;
}
if(P3IFG&BIT1){ //could be an else
//P1OUT^=BIT1;data is read from the MPC
P2DIR &= 0xFF; // put in write mode
P2OUT = *address;
//address = address + 8;
//P2OUT = *address;
__no_operation();
P2DIR &= 0x00; // put in read mode
}
P3IFG=0; // set all flags to 0
}
And the getAddress() method:
inline uint16_t getAddress(){
//uint16_t data_out = byte_MSB << 8 | byte_LSB;
uint16_t byte_MSB = P9OUT & 0b01111111;
byte_MSB = (P9OUT << 8) | (P8OUT & 0b11110000);
short byte_LSB = (P1OUT & 0b11111000) >> 3;
uint16_t total_address = byte_MSB << 1 | byte_LSB;
__no_operation();
__no_operation();
return total_address;
}