Hi all,
I am working on some code that would enable me to code a pair of MSP430 RF2500 boards to output a PWM signal with a defined Period and Duty Cycle.
However, what I would like to do is be able to give user input of a different Period and/or Duty Cycle on one board, and then be able to transmit those values to the other board, which would then change its own PWM output accordingly.
To this point, I've worked through some code(copied in below) that just pre-defines the Period and Duty Cycle with TBCCR0 and TBCCR1. Just for testing I set up the interrupt and transmission portions such that if this code is written to both boards, if I press the button on either board, the PWM output of the other board toggles. While this is good for testing, it wasn't very helpful in enabling me to solve the problem I described above, which is why I would greatly appreciate some help with this.
#include "mrfi.h"
#include "radios/family1/mrfi_spi.h"
int main(void)
{
BSP_Init(); // Initializes MSP430
P1REN |= 0x04; // Enables resistor for P1.2 (button)
P1IE |= 0x04; // Enables interrupts for P1.2.
MRFI_Init(); // Initializes CC2500-MSP430 Connection
mrfiSpiWriteReg(CHANNR, 0x13); // Changes channel for transmission.
MRFI_WakeUp(); // Wakes up Radio, puts in Idle state.
MRFI_RxOn(); // Switches Radio on.
P4SEL |= 0x10; // Sets P4.4 (Pin 9) to Timer B1
P4DIR |= 0x10; // Sets P4.4 (Extension Pin 9) as output
TBCCR0 = 50000 - 1; // (CCR0+1)/1MHz * 1000 = 50 ms
TBCCTL1 = OUTMOD_7; // OUTMOD_7 counts up to TBCCR1, then
// resets, then counts up to TBCCR0, then sets.
TBCCR1 = 20000; // (CCR1/CCR0) * 100 = 40%
BCSCTL1 = CALBC1_1MHZ; // Configures clock at 1 MHz.
DCOCTL = CALDCO_1MHZ; // Configures clock at 1 MHz.
TBCTL = TBSSEL_2 + ID_0 + MC_1 + TBCLR;
// Chooses SMCLK as source, no divider, Up-mode, clears counter
_BIS_SR(GIE + LPM0_bits); // Interrupts enabled.
}
void MRFI_RxCompleteISR() // Executes once packet is received.
{
P1OUT ^= 0x01; // Toggles Red LED on receiving board.
P4DIR ^= 0x10; // Toggles P4.4 (Extension Pin 9) as output
}
#pragma vector=PORT1_VECTOR // Executes when button is pushed.
__interrupt void Port_1 (void)
{
P1IFG &= ~0x04; // Clears interrupt flag
mrfiPacket_t packet; // Initialize packet
packet.frame[0]=8+20; // Declare Useful length?
MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); // Copy and send data
P1OUT ^= 0x02; // Toggles Green LED on transmitting board.
}
While I at least generally understand how the code works to trigger the interrupt when the button is pressed, and then transmit the packet to the other board, where the PWM output is toggled, I'm entirely confused about how to approach this problem, because I don't really get how I could input values into one board, and then have those values be transmitted to the other board. Any assistance would be greatly appreciated. Thanks!