Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 21942

MSP432P401R: How to use UCB2SDA/SCL

$
0
0

Part Number:MSP432P401R

I am working on trying to utilize the I2C ports for UCB2SDA and UCB2SCL. I am re-using code that I have written for UCB0SDA/SCL & UCB3SDA/SCL, however it does not seem to work for UCB2. I have a feeling that this has something to do with the port mapper, but I am unsure of what needs to be done in order to use UCB2 for I2C communication.

When I run the code, it completes but I am unable to see any activity on the UCB2 I2C lines using my logic analyzer. When I do not include the WithTimeout part of the send single byte, then the code gets stuck on waiting for TX receive flag inside driverlib.

I am using custom hardware with a (non-beta) MSP432P401R RGC package.

C Code: ( I run setup then init, I am only testing the STATUS portion of the code)

/*
 * LEDDriver.c
 *
 *  Created on: May 31, 2017
 *      Author: reidk
 */

#include <driverlib.h>
#include <LEDDriver.h>
#include "main.h"

// I2C Master Configuration Parameter
const eUSCI_I2C_MasterConfig LED_i2cConfig =
{
        EUSCI_B_I2C_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
        8000000,                                // SMCLK = 8MHz
        EUSCI_B_I2C_SET_DATA_RATE_100KBPS,      // Desired I2C Clock of 100khz
        0,                                      // No byte counter threshold
        EUSCI_B_I2C_NO_AUTO_STOP                // No Auto-stop
};

void LED_Setup(uint8_t module)
{
    if(module == LED_STATUS_MODULE){
        I2C_2_Current_Device = I2C_STATUS_LED;
        // Select Port 6 for I2C - Set Pin 4, 5 to input Primary Module Function, (UCB1SIMO/UCB1SDA, UCB1SOMI/UCB1SCL).
        #if LED_STATUS_SDA_PIN == GPIO_PIN6 && LED_STATUS_I2C_PORT == GPIO_PORT_P6
            MAP_GPIO_setAsPeripheralModuleFunctionInputPin(LED_STATUS_I2C_PORT, LED_STATUS_SDA_PIN + LED_STATUS_SCL_PIN, GPIO_SECONDARY_MODULE_FUNCTION);
        #else
            MAP_GPIO_setAsPeripheralModuleFunctionInputPin(LED_STATUS_I2C_PORT, LED_STATUS_SDA_PIN + LED_STATUS_SCL_PIN, GPIO_PRIMARY_MODULE_FUNCTION);
        #endif

        // Initializing I2C Master to SMCLK at 100kbs with no auto-stop
        MAP_I2C_initMaster(LED_STATUS_EUSCI_module, &LED_i2cConfig);

        // Specify slave address
        MAP_I2C_setSlaveAddress(LED_STATUS_EUSCI_module, LED_I2C_ADDRESS);

        // Set Master in transmit mode
        MAP_I2C_setMode(LED_STATUS_EUSCI_module, EUSCI_B_I2C_TRANSMIT_MODE);

        // Enable I2C Module to start operations
        MAP_I2C_enableModule(LED_STATUS_EUSCI_module);

        // Enable and clear the interrupt flags todo make transmit interrupts in the define page
        MAP_I2C_clearInterruptFlag(LED_STATUS_EUSCI_module, EUSCI_B_I2C_TRANSMIT_INTERRUPT1 + EUSCI_B_I2C_RECEIVE_INTERRUPT1);

        //Enable master Receive interrupt
        MAP_Interrupt_enableInterrupt(LED_STATUS_EUSCI_moduleINT);

        I2C_2_Current_Device = I2C_NONE;
    }else{
        I2C_1_Current_Device = I2C_COLLAR_LED;
        // Select Port 6 for I2C - Set Pin 4, 5 to input Primary Module Function, (UCB1SIMO/UCB1SDA, UCB1SOMI/UCB1SCL).
        #if LED_COLLAR_SDA_PIN == GPIO_PIN6 && LED_COLLAR_I2C_PORT == GPIO_PORT_P6
            MAP_GPIO_setAsPeripheralModuleFunctionInputPin(LED_COLLAR_I2C_PORT, LED_COLLAR_SDA_PIN + LED_COLLAR_SCL_PIN, GPIO_SECONDARY_MODULE_FUNCTION);
        #else
            MAP_GPIO_setAsPeripheralModuleFunctionInputPin(LED_COLLAR_I2C_PORT, LED_COLLAR_SDA_PIN + LED_COLLAR_SCL_PIN, GPIO_SECONDARY_MODULE_FUNCTION);
        #endif

        // Initializing I2C Master to SMCLK at 100kbs with no auto-stop
        MAP_I2C_initMaster(LED_COLLAR_EUSCI_module, &LED_i2cConfig);

        // Specify slave address
        MAP_I2C_setSlaveAddress(LED_COLLAR_EUSCI_module, LED_I2C_ADDRESS);

        // Set Master in transmit mode
        MAP_I2C_setMode(LED_COLLAR_EUSCI_module, EUSCI_B_I2C_TRANSMIT_MODE);

        // Enable I2C Module to start operations
        MAP_I2C_enableModule(LED_COLLAR_EUSCI_module);

        // Enable and clear the interrupt flags todo make transmit interrupts in the define page
        MAP_I2C_clearInterruptFlag(LED_COLLAR_EUSCI_module, EUSCI_B_I2C_TRANSMIT_INTERRUPT1 + EUSCI_B_I2C_RECEIVE_INTERRUPT1);

        //Enable master Receive interrupt
        MAP_Interrupt_enableInterrupt(LED_COLLAR_EUSCI_moduleINT);

        I2C_1_Current_Device = I2C_NONE;
    }

}

void LED_Init(uint8_t mod){
    int module;
    if(mod == LED_STATUS_MODULE){
        I2C_2_Current_Device = I2C_STATUS_LED;
        module = LED_STATUS_EUSCI_module;
    }else{
        I2C_1_Current_Device = I2C_COLLAR_LED;
        module = LED_COLLAR_EUSCI_module;
    }

    //LED_STATUS_EUSCI_TXBuffer &= 0x00;                   // Clear Transmit Buffer
    MAP_I2C_masterSendSingleByteWithTimeout(LED_STATUS_EUSCI_module, LED_CONFIG_SHDN, 1000);     //turn device off
    MAP_I2C_masterSendSingleByteWithTimeout(LED_STATUS_EUSCI_module, LED_CONFIG_IMAX | LED_MAX_CURRENT, 1000);  //setup the max current
    MAP_I2C_masterSendSingleByteWithTimeout(LED_STATUS_EUSCI_module, LED_CONFIG_PWM1 | LED_MAX_CURRENT, 1000);  //turn on 1
    MAP_I2C_masterSendSingleByteWithTimeout(LED_STATUS_EUSCI_module, LED_CONFIG_PWM2, 1000);  //turn off 2
    MAP_I2C_masterSendSingleByteWithTimeout(LED_STATUS_EUSCI_module, LED_CONFIG_PWM3, 1000);  //turn off 3

    if(mod == LED_STATUS_MODULE){
        I2C_2_Current_Device = I2C_NONE;
    }else{
        I2C_1_Current_Device = I2C_NONE;
    }
}


void LED_Interrupt(void)
{
//no receives should happen
//the led driver is write only


}

Header File:

/*
 * LEDDriver.h
 *
 *  Created on: May 31, 2017
 *      Author: reidk
 */

#ifndef LEDDRIVER_H_
#define LEDDRIVER_H_

#define LED_I2C_ADDRESS         0x39
#define LED_MAX_CURRENT         0X1F

#define LED_CONFIG_SHDN         0x00
#define LED_CONFIG_IMAX         0x20
#define LED_CONFIG_PWM1         0x40
#define LED_CONFIG_PWM2         0x60
#define LED_CONFIG_PWM3         0x80
#define LED_CONFIG_UPWARD       0xA0
#define LED_CONFIG_DWNWRD       0xC0
#define LED_CONFIG_GRAD         0xE0

#define LED_STATUS_MODULE       0
#define LED_STATUS_I2C_PORT     3
#define LED_STATUS_SDA_PIN      6
#define LED_STATUS_SCL_PIN      7

#define LED_STATUS_EUSCI_module     EUSCI_B2_BASE   // I2C module
#define LED_STATUS_EUSCI_moduleINT  INT_EUSCIB2     // Enable interrupt for the specified I2C module
#define LED_STATUS_EUSCI_TXBuffer   UCB2TXBUF       // I2C transmit buffer register

#define LED_COLLAR_MODULE       1
#define LED_COLLAR_SDA_PIN      6
#define LED_COLLAR_SCL_PIN      7
#define LED_COLLAR_I2C_PORT     1

#define LED_COLLAR_EUSCI_module     EUSCI_B0_BASE   // I2C module
#define LED_COLLAR_EUSCI_moduleINT  INT_EUSCIB0     // Enable interrupt for the specified I2C module
#define LED_COLLAR_EUSCI_TXBuffer   UCB0TXBUF       // I2C transmit buffer register

void LED_Interrupt(void);
void LED_Init(uint8_t mod);
void LED_Setup(uint8_t module);


#endif /* LEDDRIVER_H_ */


Viewing all articles
Browse latest Browse all 21942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>