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

CCS/MSP432P401R: TIMER_A and multiple PWM outputs - tips requested

$
0
0

Part Number:MSP432P401R

Tool/software: Code Composer Studio

hello,

I modified successfully a demo MSP432P401R code, originally called timer_a_pwm_mode.c (relevant section copied below).

I would like to extend this code to generate a 2nd PWM output on P2.5, which is Table 6-45 Default Mapping (Port Mapping Controller/Port Mapping Definitions)

PDF SLAS826G –MARCH 2015–REVISED SEPTEMBER 2017

"MSP432P401R, MSP432P401M SimpleLink™ Mixed-Signal Microcontrollers" indicated as:

PIN NAMEPxMAPy MNEMONICINPUT PIN FUNCTIONOUTPUT PIN FUNCTION
P2.5/PM_TA0.2PM_TA0CCR2ATA0 CCR2 capture input CCI2ATA0 CCR2 compare output Out2
P2.4/PM_TA0.1(1)PM_TA0CCR1ATA0 CCR1 capture input CCI1ATA0 CCR1 compare output Out1

So I am confused here (please help): How does one practically use DriverLib to define Capture-and-Count Register 2 (the 2nd one) and generate a 2nd type of PWM signal unrelated to the first PWM signal except for phase and route it to P2.5 ? 

Is it necessary to define a new "Timer_A_PWMConfig" as pwmConfig2 and then invoke "MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig2)" ? But does that mean we have to repeat the values of : clockSource,  clockSourceDivider,  timerPeriod; dutyCycle ? Can they be different between PWMs ?

Thanks.


/*******************************************************************************
 * MSP432 Timer_A - Variable PWM
 *
 * Description: In this example, the Timer_A module is used to create a precision 
 * PWM with an adjustable duty cycle. The PWM initial period is 200 ms and is
 * output on P2.4. The initial duty cycle of the PWM is 10%, however when the
 * button is pressed on P1.1 the duty cycle is sequentially increased by 10%.
 * Once the duty cycle reaches 90%, the duty cycle is reset to 10% on the
 * following button press.
 *
 *                MSP432P401
 *             ------------------
 *         /|\|                  |
 *          | |                  |
 *          --|RST         P1.1  |<--Toggle Switch (increase duty cycle by 10%)
 *            |            P1.4  |<--Toggle Switch (decrease duty cycle by 10%)
 *            |                  |
 *            |            P2.4  |--> Output PWM
 *            |                  |
 *            |                  |
 *
 *            **SH 1/22/19 ** When P1.4 SW is pressed LED is toggled
 *
 *******************************************************************************/
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>

/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>

//![Simple Timer_A Config]
/* Timer_A PWM Configuration Parameter */
/* Configuring Timer_A to have a period of approximately 500ms and
 * an initial duty cycle of 10% of that (3200 ticks)  */
Timer_A_PWMConfig pwmConfig =
{
 TIMER_A_CLOCKSOURCE_SMCLK,
 TIMER_A_CLOCKSOURCE_DIVIDER_1,
 32000,
 TIMER_A_CAPTURECOMPARE_REGISTER_1,
 TIMER_A_OUTPUTMODE_RESET_SET,
 3200
};
//![Simple Timer_A Config]

int main(void)
{
    /* Halting the watchdog */
    MAP_WDT_A_holdTimer();

    //![Simple Timer_A Example]
    /* Setting MCLK to REFO at 128Khz for LF mode
     * Setting SMCLK to 64Khz */
    MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
    MAP_CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2);
    MAP_PCM_setPowerState(PCM_AM_LF_VCORE0);

    /* Configuring GPIO2.4 as peripheral output for PWM  and P1.1 for increase button
     * interrupt and P1.4 for decrease button interrupt */
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,
                                                    GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN4);
    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN4);
    MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN4);


    /* **SH** Configure GPIO1.0 (RED LED) as indicator */
    // Set P1.0 to output direction
       GPIO_setAsOutputPin(
           GPIO_PORT_P1,
           GPIO_PIN0
           );

    /* Configuring Timer_A to have a period of approximately 500ms and
     * an initial duty cycle of 10% of that (3200 ticks)  */
    MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
    //![Simple Timer_A Example]

    /* Enabling interrupts and starting the watchdog timer */
    MAP_Interrupt_enableInterrupt(INT_PORT1);
    MAP_Interrupt_enableSleepOnIsrExit();
    MAP_Interrupt_enableMaster();

    /* Sleeping when not in use */
    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}

/* Port1 ISR - This ISR will progressively step up the duty cycle of the PWM
 * on a button press
 */
void PORT1_IRQHandler(void)
{
    uint32_t status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
    MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);

    if (status & GPIO_PIN1)
    {
        if(pwmConfig.dutyCycle == 28800)
            pwmConfig.dutyCycle = 3200;
        else
            pwmConfig.dutyCycle += 3200;

        MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
    }

    if (status & GPIO_PIN4)
    {
        if(pwmConfig.dutyCycle == 3200)
            pwmConfig.dutyCycle = 28800;
        else
            pwmConfig.dutyCycle -= 3200;

        MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);

        // Toggle P1.0 output
        GPIO_toggleOutputOnPin(
                GPIO_PORT_P1,
                GPIO_PIN0
        );
    }



}


CCS/MSP430F449: msp430f449

$
0
0

Part Number:MSP430F449

Tool/software: Code Composer Studio

hi

i need to calculate delayfunction using looping function not with timer.
due to have any sample code on this

i have used 32khz as first crystal and 8 mhz as second crystal

because i tried so much on the net nothing works as for clock register is concerned i am using default values

regards
senthil

Linux/MSP432P401R: MSP432401R

$
0
0

Part Number:MSP432P401R

Tool/software: Linux

 Hi Team,

We are trying to program a MSP432401R via JTAG using the connection mentioned in https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/629883 from another MSp432401R board. The issue after doing this setup is if we try to program the MSP432 via Uniflash we get an Error -615 @ 0x0 . Could you let us know the setting that should be done on Uniflash for programming the msp432 through XDS110 probe via JTAG.

Also after failing to program MSP432 using JTAG method, if we try to program the msp432401r via USB using Uniflash we still encounter the error Error -615 @ 0x0. On probing the JTAG pins looks the like the JTAG pins are set to high. Is there any way we can resolve this issue. Also the MSP432 chip is working as we are able to run the program resident on MSP432 on reset.

Thanks,

Neetha.

EVM430-FR6047: d

$
0
0

Part Number:EVM430-FR6047

Hi,

I'm using USS_02_20_00_15 and UltrasonicWaterFR604x_02_20_00_04.

I tried calibration according to the flow chart I received.

What I did was :

1. configure parameter check. [waveform & ADC capture result]

2. calibration table setting. [I tried two methods, (1)runtime calib, (2)manual calib]

figure 1. Calibration Table Setting.

3. generate header in configuration tab [I tried two methods, (1)check adv, calibration Table (2) not check adv. calibration table

4. modify demo code. In usslibguiapp_init() function, comment out line of code.

//gUssSWConfig.algorithmsConfig->numOfMeterCalibrationRanges = 0;

5. recompile target board.

6. connect GUI & board, testing.

The results are as follows.

figure 2. At a flow rate of 98 L / h, adv. calibration table check

figure 3. At a flow rate of 98 L / h, adv. calibration table not check

The result of not using the calibration function. [figure 4]

figure 4. The result of not using the calibration function. 98L/h

Wrong way to use the calibration function?

Please let me know how to resolve this issue.

Best Regards,

CCS/MSP-TS430DA38: MSP430F2252

$
0
0

Part Number:MSP-TS430DA38

Tool/software: Code Composer Studio

hi sir,

    i want to know about execution time in msp430f2252 using CCS. i already used IAR there given gettick function.but in CCS function name and how to use can explain details of that.

thanking you

siranjeevi

EVM430-FR6047: EVM430-FR6047: What is the difference between "AUTO mode" and "Ultra low power mode".

$
0
0

Part Number:EVM430-FR6047

Hello,

I am interested in knowing the difference between "AUTO mode" and "Ultra low power mode" regarding the measurement control (apart from an additional "holdoff time" in ultra low power mode.)

Regards,

Mr. Jadhav

EVM430-FR6047: USS calibration slope & offset equation

$
0
0

Part Number:EVM430-FR6047

Hi.

At the USS Design center, The result is slope and offset, if the user enters two points of expected vfr and mean vfr.

i think It differs from the method of obtaining general slope and intercept. is that right?

if so, Can you tell me an equation to calculate slope and offset?

Compiler/MSP430F5419A: Erased memory from struct when exit of function

$
0
0

Part Number:MSP430F5419A

Tool/software: TI C/C++ Compiler

Hi all,

i made a application to comunicate the msp430 with mxt640t. the msp430 read the registers of this chip.

mxt_ReadInformationBlock(mxt_data data)

i do a struct "mxt_data  data" where i store the readings.

typedef struct{
	
        mxt_platform_data *pdata;
       
        /*!  the struct containing ID Information. */
	InfoId_t info;
        
        /*!an array of objects  information*/
        Object_t object_table[43];
        
        
        /*! Information block checksum struct*/
         CRC checksum;

         /*! Information block checksum 32 bits*/
          unsigned long lCrc; //Calculated checksum variable
          
          
          /*! Raw info block data */
         unsigned char *raw_info;
         
         /*! Number of valid report IDs */
        unsigned int max_report_id;
        
        /*!
 * @brief Struct holding the object type / instance info.
        *
 * Struct holding the object type / instance info. An array of these maps
 
        * report id's to object type / instance (array index = report id). 
        Note
 * that the report ID number 0 is reserved.
 */
        Report_Id_Map_t report_id_map[80];
        
}mxt_data ;

/*! \brief Object table element struct */
typedef struct
{ 
  unsigned char Type;  /*!< Object type ID */
  unsigned char LSB;   /*!< LSByte of the start address of the obj config structure */
  unsigned char MSB;   /*!< MSByte of the start address of the obj config structure */
  unsigned char Size_minus_one;   /*!< Byte length of the obj config structure - 1 */
  unsigned char Num_Instances_minus_one;   /*!< Number of objects of this obj. type - 1 */
  unsigned char Num_ReportID;     /*!< The max number of touches in a screen,
                                 
                                  *  max number of sliders in a slider array, etc.*/

}Object_t;

the problem is when the program exit the function and the registers stored in "data.object_table" are erased.

int TactilI2C::mxt_ReadInformationBlock(mxt_data data)
/*----------------------------------------------------------------------------*/
/** \brief

all blocks read of information: id information and object table \param register: Buffer mem \return 1: CRC OK lectura correcta 0: CRC incorrecto, lectura incorrecta ERR_TIMEOUT: Error timeout \remarks *******************************************************************************/ { int status =0; int error=0; int num_objects = data.info.Num_Obj_Declared; int crc_area_size = sizeof(InfoId_t) + num_objects * sizeof(Object_t); int info_block_size = crc_area_size + sizeof(CRC); unsigned char *Info_Block; //pointer to first object int j=0; for(int i=7; i<=crc_area_size; i+=6) { error = mxt_ReadRegister(Info_Block,(unsigned char)i,crc_area_size); data.object_table[j].Type=mcRxBuffTact[0]; data.object_table[j].LSB=mcRxBuffTact[1]; data.object_table[j].MSB=mcRxBuffTact[2]; data.object_table[j].Size_minus_one=mcRxBuffTact[3]; data.object_table[j].Num_Instances_minus_one=mcRxBuffTact[4]; data.object_table[j].Num_ReportID=mcRxBuffTact[5]; j++; } return ERR_OK; }
as you can see in this function "mxt_ReadInformationBlock(mxt_data data)" reads the registers of mxt640 and stored the data in the data.object_table struct.
 When the function exit, the data previously stored is erased. Due to software requeriments ans for lack of memory i have to modify stack heap memory to 1800 to 1780 , i think this won't be a problem,
but maybe this info is useful.

anyone know how it is  posible?

thanks in advance


MSP430FR6047: Measurement time

$
0
0

Part Number:MSP430FR6047

Im trying to measure with USS through USSLib (v. 2.20) and whole measurement takes about 200 ms. I made one GPIO to change value after every part of measurement process and its shown on osciloscope screen below.  I use methods USS_configureUltrasonicMeasurement(&gUssSWConfig) - 120 ms,  USS_initAlgorithms(&gUssSWConfig) - 15 ms, USS_startLowPowerUltrasonicCapture(&gUssSWConfig) - 10 ms, USS_runAlgorithms(&gUssSWConfig, &algorithms_Results) - 61 ms and flow rate addition to variables - 790 us. MCU is in LPM4.5 till next interrupt from RTC. Its normal for measurement to take so long? 

So in conclusion, is it hardware or software problem or its usual behaviour? 

Thanks

License questions

$
0
0
I'm also searching this licences and a lot of more in the same subdirectories:
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/ti/drivers/GPIO.h
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/ti/drivers/gpio/GPIOMSP432.h
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/ti/devices/msp432p4xx/inc/msp.h
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/ti/devices/msp432p4xx/inc/...
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/ti/devices/msp432p4xx/driverlib/lcd_f.h
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/ti/devices/msp432p4xx/driverlib/...
C:/ti/simplelink_msp432p4_sdk_2_30_00_14/source/third_party/CMSIS/Include/cmsis_ccs.h


Does they all have the same licences because all files from C:/ti/simplelink_msp432p4_sdk_2_30_00_14/... ?

MSP-GANG: Msp-Gang programmer unreliable

$
0
0

Part Number:MSP-GANG

I have just purchased a new MSP-Gang programmer, that is being used to program 8 MSP430FR5994 at the same time.  

The programmer has been set up and run in interactive and standalone. For an hour the unit worked perfectly and it programmed all the boards.

However after a while it was unreliable and would randomly fail to work giving various errors when running even on boards it had already passed.

It has no consistency in its function, to check we put a scope on the pcb while we did an erase check and instead of getting a steady square wave we got anything but.

The self test says no errors in the unit, it is being powered with a 9v 2250mA psu and vcc is pin 2, we are SBC and using pins 1,2,7 and 9 only

I have made a cable that is only 60mm long and it still randomly fails to pass a board.

The errors will be random on the same pcb everytime, error 23, error 33, error 58. then the pcb will pass several times and then it will randomly fail.

If i place a new pcb on the tester it will pass a few times and then the same thing.

If i use a single MSP-FET programmer the pcb's pass every single time with no failures and on repeated runs on each pcb.

Could there possibly be an issue with the unit?

Thanks

 

MSP430F5438: Programming device from RAM without BSL

$
0
0

Part Number:MSP430F5438

Hi there,

I have a need to remove all of the firmware on my device and replace it with new firmware (which is a subset of the old firmware).

I have written code to load the various functions I need to RAM and perform a mass erase. This all works fine and I can verify it.

I also have the new code in RAM to be written back to flash. Writing these instructions to flash is trivial, but I am finding it tricky to work out where to put the instructions, or, where to update the pointer to the first instruction.

Basically, the code is in flash but doesn't run.

I have seem something about the address 0x17FA - this stores the address of the first instruction? Is it here that I need to put the memory address of my newly written flash? There are various signatures as well, do I need to update these in some way? I have already accidentally bricked a device!

I do not have the BSL still running on the device - I have completely deleted it if that makes a difference.

Cheers,

Tom

Compiler/MSP430FR5969: No error when attempting to store non-const variables in info memory?

$
0
0

Part Number:MSP430FR5969

Tool/software: TI C/C++ Compiler

I just finished debugging an issue with calibration data that I was storing in info memory. Originally, I had defined them as consts, and they were being stored correctly in info memory (using the #pragma SET_DATA_SECTION(".infoB")). At some point my compiler optimization setting must have gotten cranked up, because they were being optimized out of existence in two source files, but not a third (I can see different optimization settings in my makefile for the different files). Eventually I realized they needed to be modified as "volatile const"s not just consts, and that solved the problem.

But, in debugging the problem I saw some behavior that I don't understand... When I removed the const modifier, so they were just declared variables, they still didn't get written into info memory. This makes sense to me because you wouldn't want to put a variable in protected memory, but why didn't the linker throw an error when it couldn't fulfill the pragma SET_DATA_SECTION request? This is the sort of detail which often leads to the discovery of a bigger bug waiting to bite me, so I'd like to understand the behavior.

Thanks!

Paul

MSP430FR5969-SP: M4FR5969SRGZT-MLS external oscillator

$
0
0

Part Number:MSP430FR5969-SP

Hello,

I'd like to know if we can hook a high frequency crystal between PJ.6 and PJ.7 on the MSP430FR5969-SP (specifically the M4FR5969SRGZT-MLS).

There is some confusion as the datasheet for the MSP430FR5969-SP (http://www.ti.com/lit/ds/symlink/msp430fr5969-sp.pdf) has a note on page 15 (terminal PJ.6/HFXIN and PJ.7/HFOUT) about the external oscillator, but state that it is available on MSP430FR595x part only.

On page 2 of the datatsheet for 595x part (http://www.ti.com/lit/ds/symlink/msp430fr5959.pdf) it says the pins are available for BOTH the 596x and 595x.

Thank you

 

 

 

CCS/MSP430FR2355: SPI problem in MSP430 with NRF24L01

$
0
0

Part Number:MSP430FR2355

Tool/software: Code Composer Studio

Hi,

  I'm pretty new to the MSP430. I'm trying to connect MSP430fr2355 with NRF24L01 by SPI interface.

  I find a library related to this. Here is the library website: github.com/.../msprf24

  I follow the library and construct my SPI code, but it doesn't read the NRF24 register. 

  Problem: I put " r_result " in expressions in debug mode, it cannot change. It seems to have something wrong. 

  Here is the code: SCK(1.5); MOSI(2.0); MISO(2.2); CSN(1.6); CE(1.4); IRQ(1.7)

-------------------------------------------------------------------------------------------------------------------------------------------

#include <msp430.h>
#include <stdint.h>
#include <nRF24L01.h>

void csn_high (void);
void csn_low (void);
void ce_high (void);
void ce_low (void);
void delay (unsigned long); unsigned long wait;
void spi_ini (void);
unsigned char spi_basic (unsigned char); uint8_t data;
unsigned char spi_r (uint8_t); uint8_t addr; uint8_t rf24_status; uint8_t r_result;
void spi_w (uint8_t, uint8_t); uint8_t val;

int i;
unsigned char TxData;

int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
spi_ini();

i=1000;
while(1){
spi_w(0x00, 0x02);
TxData = UCA0TXBUF;
spi_r(0x00);

if (i>800){ // For debug test
i--;}
}
}

void csn_high (void)
{
P1OUT |= BIT6;
}
void csn_low (void)
{
P1OUT &= ~BIT6;
}
void ce_high (void)
{
P1OUT |= BIT4;
}
void ce_low (void)
{
P1OUT &= ~BIT4;
}
void delay (unsigned long wait)
{
while (--wait != 0);
}
void spi_ini (void)
{
P1DIR |= BIT6;
P1DIR |= BIT4;
P1SEL0 |= BIT5; P1DIR |= BIT5;
P2SEL0 |= BIT0; P2DIR |= BIT0;
P2SEL0 |= BIT2; P2DIR &= ~BIT2;
P1DIR |= BIT7;

ce_high();

UCA0CTLW0 |= UCSWRST;
UCA0MCTLW = 0x00;
UCA0CTLW0 |= UCMST|UCSYNC|UCCKPH|UCMSB|UCMODE0;
UCA0CTLW0 |= UCSSEL__SMCLK;
UCA0BR0 |= 0x01;
UCA0BR1 |= 0x00;

}
unsigned char spi_basic (unsigned char data)
{
UCA0TXBUF = data;
while ( !(UCA0IFG & USCI_SPI_UCRXIFG) );
return UCA0RXBUF;
}
unsigned char spi_r (uint8_t addr)
{
csn_high();
rf24_status = spi_basic (RF24_R_REGISTER | addr);

r_result = spi_basic (RF24_NOP);

csn_low();
return r_result;
}
void spi_w (uint8_t addr, uint8_t val)
{
csn_high();
rf24_status = spi_basic (RF24_W_REGISTER | addr);
spi_basic (val);
csn_low();
}

------------------------------------------------------------------------------

If anyone can help me, I’m so grateful!!!


MSP430F5659: Mass erase using the USB BSL

$
0
0

Part Number:MSP430F5659

Hi,

I want to perform a mass erase using the TI USB BSL on my MSP430F5659 via USB. Is there a GUI that exists? I have downloaded MSP430USBDEVPACK, MSP430_USB_Firmware_Upgrade_Example, and BSL scripter, but haven't been able to easily do a mass erase. I think the BSL scripter would do the job, but it looks like I need to write a script. Is there an example or something that exists? Also, from the source code of BSL_USB_GUI, there are references to MASS_ERASE, but the GUI does not have the option of just doing that.

Thank you,

Fred

CCS/MSP430F5359: MSP430f5359 crystal oscillator is not working in custom board

$
0
0

Part Number:MSP430F5359

Tool/software: Code Composer Studio

Attach is the schematic and PCB layout of a custom design board for my project, the crystal oscillator is not working. I'm using Msp430f5359, is there anything working with  the schematic and layout?

MSP432E401Y: Can't get static IP to work in lwIP

$
0
0

Part Number:MSP432E401Y

Hello, using the MSP-EXP432E401Y dev kit, I imported  into my workspace this example:

http://dev.ti.com/tirex/#/?link=Software%2FSimpleLink%20MSP432E4%20SDK%2FExamples%2FDevelopment%20Tools%2FMSP432E401Y%20LaunchPad%2FlwIP%2Fethernet_with_lwip

The code works fine when I use DHCP. However, when I try to use a statip IP, it fails.

In the file enet_lwip.c I change this line:

lwIPInit(g_ui32SysClock, pui8MACArray, 0, 0, 0, IPADDR_USE_DHCP);

to this:

ip4_addr_t local;
ip4_addr_t netmask;
ip4_addr_t gateway;


IP4_ADDR(&local,   192, 168, 1  ,19);
IP4_ADDR(&netmask, 255, 255, 255,0);
IP4_ADDR(&gateway, 192, 168, 1  ,1);

lwIPInit(g_ui32SysClock, pui8MACArray, local.addr, netmask.addr, gateway.addr, IPADDR_USE_STATIC);

with no sucess. I'm using the latest version of the SimpleLink SDK(2.40.00.11)

Any help would be appreciated.

Thanks,

Richard

MSP430F5659: Interrupt Detect On both Edge

$
0
0

Part Number:MSP430F5659

Hi all,

I am connected a switch (on/off switch) with a custom board board of MSP430F5659. The interrupt configured for this is in HIGH_TO_LOW transition,

But interrupt takes place int both edges. The scenario is like when the switch is on one interrupt generated, when the switch turned  off there also a interrupt generated.

What may be the reason for that, Kindly Help

Attaching my code

int main(void)
{

//clock() 8MHz

    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P4,GPIO_PIN4);
    GPIO_enableInterrupt(GPIO_PORT_P4,GPIO_PIN4);
    GPIO_selectInterruptEdge(GPIO_PORT_P4,GPIO_PIN4,GPIO_HIGH_TO_LOW_TRANSITION);
    GPIO_clearInterrupt(GPIO_PORT_P4,GPIO_PIN4);

while(1)

{

}

}

#pragma vector=PORT4_VECTOR
__interrupt void Port_4(void)
{

        case P4IV_P4IFG4:                                      
            if (P4IES & BIT4)
            {
              //interrupt generated
                GPIO_clearInterrupt(GPIO_PORT_P4,GPIO_PIN4);
            }
            break;

}

Regards,

Renjith

MSP430FR4133: External Sensor MCP9808 interfacing with MSP430FR4133

$
0
0

Part Number:MSP430FR4133

Part Number:MSP430FR4133

Tool/software: IAR Embedded

 Hello,

 I'm a beginner on MSP430 and programming, and need some help with a project of mine.

Project- To interface an external temperature sensor MCP9808 through I2C communication with MSP430FR4133 to get temperature value.

Connections

SDA- pin 5.2

SCL- pin 5.3

GND-GND

VDD- 3.3V

I have interfaced a temperature sensor  MCP9808 with MSP430FR4133 through i2c communication. I am using the following code to read the temperature value from the sensor. I couldn't find the required results to get temperature value.

I am facing problem to get the desired results.

In MCP9808 data sheet in CONFIG Register part where I have to write

Addressbyte(0x30),Configuration pointer (0x01), MSB(0x00), LSB (0x08)

and read out Addressbyte(0x31), (0x00), (0x08) as a desired result but I am reading out Addressbyte(0x31), (0x00), (0x18), (0x01).

I have attached results below which are taken by logic analyzer. Any guidance to help me understand where I am doing mistake will be appreciated.

#define I2C__MSP430FR4133_H_

#include <MSP430.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "usci.h"

#define AMBIENT_TEMPERATURE		0x05
//#define Configuration_Reg		0x01
#define DEVICE_ID_REGISTER  		0x04
#define MANUFACTURE_ID_REGISTER	        0x0054
//#define AdressByte         	        0x30


 uint16_t tlen = 0;
 uint16_t rlen = 0;
 int *tx = NULL;
 int *rx = NULL;
 uint8_t addr = 0x18;
// void *tx =(void *)0x01;
// void *rx =(void *)0x00;

 
 
volatile unsigned char RXData;
volatile unsigned char TXData;

long Temperature;
void Stop_WD (void);
uint16_t I2C_TempRead(void);
uint16_t I2C_readMode(void);
void delay_tick(uint16_t);


unsigned char Adressbyte[10]; 
unsigned char Transmit [10]; 
unsigned char Meas_Receive [10];


int main(void)
{
 
  Stop_WD();
    
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5; 
Set_I2C();
//Transmit [0] =0x30 & 0xFE;
Transmit [0] = 0x01;
Transmit [1] = 0x00;
Transmit [2]=  0x08;

Meas_Receive [0] = 0x07;


__bis_SR_register(GIE);

I2C_write(&Transmit[0],3,addr);

delay_tick(500);

Set_I2C();

I2C_write_read (&Transmit[0],1,&Meas_Receive [0],3,addr);
//I2C_write(&Transmit[0],1,addr);
//I2C_read(&Meas_Receive [0],2,addr);

//I2C_readMode();
//I2C_TempRead();
//      
    while (1)
    {
        __delay_cycles(2000);
        while (UCB0CTL1 & UCTXSTP);         // Ensure stop condition got sent
        UCB0CTL1 |= UCTXSTT;                // I2C start condition
      
        __bis_SR_register(LPM0_bits|GIE);   // Enter LPM0 w/ interrupt
    }
}



#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCIB0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
  {
    case USCI_NONE:          break;         // Vector 0: No interrupts
    case USCI_I2C_UCALIFG:   break;         // Vector 2: ALIFG
    case USCI_I2C_UCNACKIFG:                // Vector 4: NACKIFG
      UCB0CTL1 |= UCTXSTT;                  // resend start I2C start condition
      break;
    case USCI_I2C_UCSTTIFG:  break;         // Vector 6: STTIFG
    case USCI_I2C_UCSTPIFG:          // Vector 8: STPIFG
     TXData = 0;
     UCB0IFG &= ~UCSTPIFG;                 // Clear stop condition int flag
     break;
    case USCI_I2C_UCRXIFG3:  break;         // Vector 10: RXIFG3
    case USCI_I2C_UCTXIFG3:  break;         // Vector 14: TXIFG3
    case USCI_I2C_UCRXIFG2:  break;         // Vector 16: RXIFG2
    case USCI_I2C_UCTXIFG2:  break;         // Vector 18: TXIFG2
    case USCI_I2C_UCRXIFG1:  break;         // Vector 20: RXIFG1
    case USCI_I2C_UCTXIFG1:           // Vector 22: TXIFG1
//      UCB0TXBUF = TXData++;
      break; 
    case USCI_I2C_UCRXIFG0:                 // Vector 24: RXIFG0
      RXData = UCB0RXBUF;                   // Get RX data
      __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
      break;
    case USCI_I2C_UCTXIFG0:  break;         // Vector 26: TXIFG0
    case USCI_I2C_UCBCNTIFG: break;         // Vector 28: BCNTIFG
    case USCI_I2C_UCCLTOIFG: break;         // Vector 30: clock low timeout
    case USCI_I2C_UCBIT9IFG: break;         // Vector 32: 9th bit
    default: break;
  }
}

void Stop_WD (void)
 {
   WDTCTL = WDTPW | WDTHOLD;                                    // Stop WDT
 }
//
//
//void Device_ID(uint8_t device_reg)
//{
// 
//}
//
//void Manufacture_ID(uint8_t manufacture_reg)
//{
//  
//}
//
//void Ambient_Temp(uint8_t ambient_temp_reg)
//{
//  
//}                                                                                                                                                                            



uint16_t I2C_readMode(void)
{
  uint8_t UpperByte = 0;
  uint8_t LowerByte = 0;
  uint16_t data = 0;
  
//  UpperByte = i2c_read(); // READ 8 bits
////and Send ACK bit
//LowerByte = i2c_read(); // READ 8 bits
////and Send NAK bit
  
 data = UpperByte<<8|LowerByte;
 return data;
}

uint16_t I2C_TempRead(void)
{
 uint8_t UpperByte = 0; 
 uint8_t LowerByte = 0;
 uint16_t Temperature = 0;
 
 
 //Convert the temperature data
//First Check flag bits
if ((UpperByte & 0x80) == 0x80)
{                                                       //TA ³ TCRIT
}
if ((UpperByte & 0x40) == 0x40)
{                                                       //TA > TUPPER
}
if ((UpperByte & 0x20) == 0x20)
{                                                       //TA < TLOWER
}
UpperByte = UpperByte & 0x1F;                           //Clear flag bits

if ((UpperByte & 0x10) == 0x10)
{                                                       //TA < 0°C
UpperByte = UpperByte & 0x0F;                           //Clear SIGN
Temperature = 256 - (UpperByte * 16 + LowerByte / 16);
}
else 
{                                                       //TA ³ 0°C
Temperature = (UpperByte * 16 + LowerByte / 16);
                                                        //Temperature = Ambient Temperature (°C)
}
return Temperature;
}

void delay_tick(uint16_t tick)
{
  for (uint16_t i=0;i<tick; i++);
}


//----------------------------------------------I2C--------------------------------//

void Set_I2C(void)
{
  P5SEL0 |= BIT2 | BIT3;                  // I2C pins
 // Configure USCI_B0 for I2C mode 
  UCB0CTLW0 |= UCSWRST;                   // Software reset enabled
  UCB0CTLW0 |= UCMODE_3 | UCMST | UCSYNC; // I2C mode, Master mode, sync
  UCB0CTLW1 |= UCASTP_2;                  // Automatic stop generated

  UCB0BRW = 0x0008;                         // baudrate = SMCLK / 8
  UCB0TBCNT = 0x07;                       // number of bytes to be received
  UCB0I2CSA = 0x18;                       // Slave address is 0x18
  UCB0CTL1 &= ~UCSWRST;
  UCB0IE |= UCRXIE | UCNACKIE | UCBCNTIE ;
  
  
}



//------------------I2C_Master_write-------------------------------------------------//

uint32_t I2C_write(unsigned char* tx, uint32_t tlen,uint8_t addr)

{
  uint32_t r_val = 0;
  
  UCB0I2CSA = addr;                             // Assing slave address
  
  while ((UCB0IFG & UCSTPIFG));                 // Check if Stop condition on
  UCB0CTL1 |= UCTR + UCTXSTT;                   // Start writing through I2C
  while (!(UCB0IFG & UCTXIFG));                 // Wait until TX buffer ready
  for(uint32_t i = 0; i < tlen; i++) 
  {           
    UCB0TXBUF = *((uint8_t*)tx + i);            // Write string in  TX buffer of I2C        
    while (!(UCB0IFG & UCTXIFG));               // Wait until TX buffer ready
    if( i == tlen - 1) 
    {                                           // If only one byte left to write
      UCB0CTL1 |= UCTXSTP;                      // I2C stop condition
      UCB0IFG &= ~UCTXIFG;                      // Clear USCI_B0 TX int flag
    }
    r_val++;                                    // Increment return value
  }

  return r_val;
}

//----------------I2C_MASTER_READ--------------------------------------------------------//

uint32_t I2C_read(unsigned char* rx, uint32_t rlen, uint8_t addr)

{
  UCB0IFG &= ~UCSTPIFG;
  uint32_t r_val = 0;
  
  UCB0I2CSA = addr;                               // Assing slave address
  if (rlen != 0)
  {
    while ((UCB0CTL1 & UCTXSTP));                 // Check if Stop condition on
    UCB0CTL1 &= ~UCTR;                            // Set writing bit in register to 0
    UCB0CTL1 |= UCTXSTT;                          // Start reading through I2C
    while (!(UCB0CTL1 & UCTXSTT));                // start condition is not sent
    // only one byte
    if (rlen == 1)
    {
      while (!(UCB0IFG & UCRXIFG))                // wait until start condition is sent
      {
        if((UCB0CTL1 & UCTXSTT)==0)
          UCB0CTL1 |= UCTXSTP;                    // generate stop condition
      }
      while (UCB0CTL1 & UCTXSTP);                 // Ensure stop condition got sent
      *((uint8_t*)rx) = UCB0RXBUF;
      return 1;
    }
    // multiple bytes
    for (uint8_t i = 0; i < rlen-1; i++)
    {
      while (!(UCB0IFG & UCRXIFG));                // Wait until new data was written into RX buffer
      *((uint8_t*)rx + i) = UCB0RXBUF;              // Read RX buffer
      r_val ++;                                     // Increment return value      
    }
    UCB0CTL1 |= UCTXSTP;                            // Generate Stop condition  
    while (UCB0CTL1 & UCTXSTP);                     // Wait untill its generated
    *((uint8_t*)rx+rlen-1) = UCB0RXBUF;             // Read last byte 
  }
  return r_val++;
}

/*******************/

uint32_t I2C_write_read (unsigned char* tx,uint32_t tlen,unsigned char* rx, uint32_t rlen,uint8_t addr)
{
  
  uint32_t r_val = 0;
  
  UCB0I2CSA = addr;                             // Assing slave address
  
  while ((UCB0IFG & UCSTPIFG));                 // Check if Stop condition on
  UCB0CTL1 |= UCTR + UCTXSTT;                   // Start writing through I2C
  while (!(UCB0IFG & UCTXIFG));                 // Wait until TX buffer ready
  for(uint32_t i = 0; i < tlen; i++) 
  {           
    UCB0TXBUF = *((uint8_t*)tx + i);            // Write string in  TX buffer of I2C        
    while (!(UCB0IFG & UCTXIFG));               // Wait until TX buffer ready
    if( i == tlen - 1) 
    {                                           // If only one byte left to write
      UCB0CTL1 |= UCTXSTP;                      // I2C stop condition
      UCB0IFG &= ~UCTXIFG;                      // Clear USCI_B0 TX int flag
    }
    r_val++;                                    // Increment return value
  }
  
r_val = 0;
  
  if (rlen != 0)
  {
    while ((UCB0CTL1 & UCTXSTP));                 // Check if Stop condition on
    UCB0CTL1 &= ~UCTR;                            // Set writing bit in register to 0
    UCB0CTL1 |= UCTXSTT;                          // Start reading through I2C
    while (!(UCB0CTL1 & UCTXSTT));                // start condition is not sent
    // only one byte
    if (rlen == 1)
    {
      while (!(UCB0IFG & UCRXIFG))                // wait until start condition is sent
      {
        if((UCB0CTL1 & UCTXSTT)==0)
          UCB0CTL1 |= UCTXSTP;                    // generate stop condition
      }
      while (UCB0CTL1 & UCTXSTP);                 // Ensure stop condition got sent
      *((uint8_t*)rx) = UCB0RXBUF;
      return 1;
    }
    // multiple bytes
    for (uint8_t i = 0; i < rlen-1; i++)
    {
      while (!(UCB0IFG & UCRXIFG));                // Wait until new data was written into RX buffer
      *((uint8_t*)rx + i) = UCB0RXBUF;              // Read RX buffer
      r_val ++;                                     // Increment return value      
    }
    UCB0CTL1 |= UCTXSTP;                            // Generate Stop condition  
    while (UCB0CTL1 & UCTXSTP);                     // Wait untill its generated
    *((uint8_t*)rx+rlen-1) = UCB0RXBUF;             // Read last byte 
  }
  
  return r_val++; 
}

Thank you!

Mr. Shetty

Student

Viewing all 22002 articles
Browse latest View live