Skip to content

Problem generating PWM #25

Description

@LukeVance5

Hello,

I am currently trying to create an RC boat with this library. I have been usings Ikes example as a guide, and have been able to do the led blinking. I have also updated it to change led on keystroke from pc, which worked fine. Currently, I am having the issue that the reciever stops working when I enable a PWM on P1.2. I can no longer send commands from my transmitter, and the red led of failed transmission appears. The launchpad I am using is MSP430F5529LP. I thought I could change LPM4 to LPM0, but that didn't seem to work Here is my receiver code:

#include <msp430.h>
#include "intrinsics.h"
#include "msprf24.h"
#include "nrf_userconfig.h"
#include "stdint.h"

#define  TXD BIT4 // P4.4 - UART Transmitter
#define  RXD BIT5 // P4.5 - UART Receiver

volatile unsigned int user;
void init_rudder(void);
void rudder_left(void);
void rudder_right(void);
void main()
{
    char addr[5] = "00005";
    char buf[32];

    WDTCTL = WDTHOLD | WDTPW;

    // Red LED will be our output
    P1DIR |= BIT0;
    P4DIR |= BIT7;
    P1OUT &= ~BIT0;
    P1OUT &= ~BIT7;

    user = 0xFE;

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
    rf_addr_width      = 5;
    rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_0DBM;
    rf_channel         = 100;

    init_rudder();
    msprf24_init();
    msprf24_set_pipe_packetsize(0, 32);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst

    // Set our RX address
    //addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00;
    w_rx_addr(0, addr);

    // Receive mode
    if (!(RF24_QUEUE_RXEMPTY & msprf24_queue_state())) {
        flush_rx();
    }
    msprf24_activate_rx();
    void init_rudder();
    //
    //TA0CCR1 = 1500;
    LPM0;
    while (1) {
        if (rf_irq & RF24_IRQ_FLAGGED) {
            msprf24_get_irq_reason();
        }
        if (rf_irq & RF24_IRQ_RX) {
            r_rx_payload(32, buf);
            msprf24_irq_clear(RF24_IRQ_RX);
            user = buf[0];
            if (buf[0] == '0') {
                P1OUT |= BIT0;
                P4OUT &= ~BIT7;
            }   
            if (buf[0] == '1') {
                P1OUT &= ~BIT0;
                P4OUT &= ~BIT7;
                rudder_left();
            }    
            if (buf[0] == '2') {
                P4OUT |= BIT7;
                P1OUT &= ~BIT0;
            }     
            if (buf[0] == '3') {
                P4OUT |= BIT7;
                P1OUT &= ~BIT0;
                rudder_right();
            }        

        } else {
            user = 0xFF;
        }
        LPM0;
    }
}

void init_rudder(void) {
    TA0CTL = TASSEL_2 + MC_1 + TAIE +ID_0;
    TA0CCR0 = 20960; // PWM period 20ms
    TA0CCTL1 = OUTMOD_7; // TA0CCR1 reset/set-high voltage
    TA0CCR1 = 1572;
    P1DIR |= BIT2; // Output on Pin 1.2
    P1SEL |= BIT2; // Pin 1.2 selected as PWM
}

void rudder_left(void) {
    if (TA0CCR1 == 1834) {
        TA0CCR1 = 1572;
    } else {
        TA0CCR1 = 1310;
    }
}


void rudder_right(void) {
    if (TA0CCR1 == 1310) {
        TA0CCR1 = 1572;
    } else {
        TA0CCR1 = 1834;
    }
}

and here is my transmitter code:

#include <msp430.h>
#include "msprf24.h"
#include "nrf_userconfig.h"
#include "stdint.h"

volatile unsigned int user;
unsigned int TXByte;
char buf[32];
void setup_USCI_A1(void);
void main()
{
    char addr[5] = "00005";
    

    WDTCTL = WDTHOLD | WDTPW;

    // Red, Green LED used for status
    P1DIR |=  BIT0;
    P1OUT &= ~BIT0;
    P4DIR |=  BIT7;
    P4OUT &= ~BIT7;
    
    /* Initial values for nRF24L01+ library config variables */
    
    rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
    rf_addr_width      = 5;
    rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_0DBM;
    rf_channel         = 100;

    msprf24_init();  // All RX pipes closed by default
    msprf24_set_pipe_packetsize(0, 32);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs

    // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
    msprf24_standby();
    user = msprf24_current_state();
    //addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00;
    w_tx_addr(addr);
    w_rx_addr(0, addr);  // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node
                     // needs to listen to the TX addr on pipe#0 to receive them.
    setup_USCI_A1();
    while(1) {
        while (!(UCA1IFG & UCRXIFG));   // Check if data is available
            char received = UCA1RXBUF;  // Read received byte
            while (!(UCA1IFG & UCTXIFG));  // Wait for TX buffer ready
            UCA1TXBUF = received; // Echo back received byte
        if (received == '0') {
            buf[0] = '0';
        } else if   (received == '1') {
            buf[0] = '1';
        } else if (received == '2') {
            buf[0] = '2';
        } else if (received == '3') {
            buf[0] = '3';
        }
        w_tx_payload(32, buf);
        msprf24_activate_tx();   
        LPM4;
        if (rf_irq & RF24_IRQ_FLAGGED) {
            msprf24_get_irq_reason();
            if (rf_irq & RF24_IRQ_TX){
                P1OUT &= ~BIT0; // Red LED off
                P4OUT |= BIT7;  // Green LED on
            }
            if (rf_irq & RF24_IRQ_TXFAILED){
                P4OUT &= ~BIT7; // Green LED off
                P1OUT |= BIT0;  // Red LED on
            }

            msprf24_irq_clear(rf_irq);
            user = msprf24_get_last_retransmits();
        } 
    }
}

void setup_USCI_A1(void) {
    P1OUT |= BIT0;  // Red LED on
    _delay_cycles(800000);
    P1OUT &= ~BIT0;
    UCA1CTL1 = UCSWRST; //Recommended to place USCI in reset first
    P4SEL |= BIT4 + BIT5;
    UCA1CTL1 |= UCSSEL_2; // Use SMCLK
    UCA1BR0 = 109; // Set baud rate to 9600 with 1.048MHz clock (Data Sheet 36.3.13)
    UCA1BR1 = 0; // Set baud rate to 9600 with 1.048MHz clock
    UCA1MCTL = UCBRS_2; // Modulation UCBRSx = 2
    UCA1CTL1 &= ~UCSWRST; // Initialize USCI state machine
    //UCA1IE |= UCRXIE;
}
/*
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void) {
    __bis_SR_register(GIE);
    P1OUT |= BIT0;  // Red LED on
    _delay_cycles(800000);
    P1OUT &= ~BIT0;
    char received = UCA1RXBUF; // Read received byte
    while (!(UCA1IFG & UCTXIFG)); // Wait for TX buffer ready
    UCA1TXBUF = received; // Echo back
    if (received == '0') {
        buf[0] = '1';
        buf[1] = '0';
    } else {
        buf[0] = '0';
        buf[1] = '1';
    }
    w_tx_payload(32, buf);
    msprf24_activate_tx();   
    LPM4;
    if (rf_irq & RF24_IRQ_FLAGGED) {
        msprf24_get_irq_reason();
        if (rf_irq & RF24_IRQ_TX){
            P1OUT &= ~BIT0; // Red LED off
            P4OUT |= BIT7;  // Green LED on
        }
        if (rf_irq & RF24_IRQ_TXFAILED){
            P4OUT &= ~BIT7; // Green LED off
            P1OUT |= BIT0;  // Red LED on
        }

        msprf24_irq_clear(rf_irq);
        user = msprf24_get_last_retransmits();
    } 
}
*/

Is there a way for me to just pull on the receiver side and not go to sleep?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions