Other Parts Discussed in Thread: SIMPLICITI
Hi all,
I would appreciate some help with solving this problem. Essentially, what I would like to do is program a pair of MSP430 RF2500 boards so that Board A will output a PWM signal with a specified period and duty cycle, which is simple enough, and which I have already done. However, I would then like to be able to program Board B from my computer with a different set of values for the period and duty cycle, and send those values to Board A using the UART, where the values of TBCCR0 and TBCCR1 are changed, so the PWM changes as desired.
The code I have right now is pretty simple (copied below), basically just toggling the port with the PWM of Board B when I press the button on Board A, and does not use UART at all:
#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
TBCCR1= TBCCR1;
}
#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.
}
As I said above, I would like to add to this code/remove what is unnecessary so that I can just alter the code on Board A with a different set of values for the period and duty cycle, and have those values sent via UART to Board B, where the PWM output will be changed accordingly.
I've been looking through the provided examples for F2274 MSP430s that use UART, primarily msp430x22x4_uscia0_uart_01_9600.c and msp430x22x4_uscia0_uart_06_9600.c, but I'm having a lot of trouble understanding how exactly to integrate the concepts in the example into my code above. I get the feeling that it will be very simple, but for whatever reason I simply can't grasp it. Any assistance would be extremely helpful for this.
Thanks!