Ti msp430f5310

Discussion in 'Embedded Systems and Microcontrollers' started by bangaru, Jan 5, 2012.

  1. bangaru

    Thread Starter New Member

    Jan 5, 2012
    1
    0

    I am working on a project where i'm using TI micro MSP430F5310. My slave address doesn't seem to be right when i see it on oscilloscope. Can anyone help me with this problem? Why is my slave address not coming out right?

    Code ( (Unknown Language)):
    1.  
    2. #include
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1.  
    Code ( (Unknown Language)):
    1. [SIZE=2] [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<msp430f5310.h>[/COLOR][/SIZE][/COLOR][/SIZE]
    Code ( (Unknown Language)):
    1. [SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
    2. [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]unsigned[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] *PTxData; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Pointer to TX data[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    3. [/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]unsigned[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TXByteCtr;[/SIZE][/LEFT][SIZE=2]
    4. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]const[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]unsigned[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TxData[] = [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Table of data to transmit[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    5. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]{
    6. 0x11,
    7. 0x22,
    8. 0x33,
    9. 0x44,
    10. 0x55
    11. };[/LEFT]
    12. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]void[/LEFT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][/left][/COLOR][LEFT][/left][/SIZE][LEFT][SIZE=2] [B]main[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
    13. {
    14. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]unsigned[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i;
    15. WDTCTL = WDTPW + WDTHOLD; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Stop [U]Watchdog[/U] timer[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    16. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]PJDIR |= BIT1; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// PJ.1 set as output[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    17. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]P4SEL |= 0x06; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Sets P4.1 to UCB1SDA, 4.2 to UCB1SCL[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    18. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]P4DIR |= BIT6; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// set P4.6 as output[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    19. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]P4OUT |= BIT6;
    20. [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// XT2 Setup[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    21. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]P5SEL |= BIT2+BIT3; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// For XT2 crystal usage.[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    22. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
    23. [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Setting up clocks[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    24. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL0 = 0; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// set lowest possible DCOx, MODx[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    25. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL1 |= DCORSEL_4 + DCORSEL_5; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set max. DCO setting[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    26. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL2 = FLLD_1+366; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set DCO Multiplier for 12MHz[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    27. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// (N + 1) * FLLRef = [U]Fdco[/U][/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][U]
    28. [/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// (366 + 1) * 32768 = 12MHz[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    29. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set FLL [U]Div[/U] = fDCOCLK/2[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    30. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL3 = SELREF_2; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set DCO FLL reference = REFO[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    31. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL4 = SELA_5 + SELS_5 + SELM_5; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// set ACLK = XT2;SMCLK = XT2;MCLK = XT2[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    32. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL5 = DIVPA_0 +DIVA_0 + DIVS_3 + DIVM_3; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// set all dividers[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    33. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL6 |= XT2DRIVE_1; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// XT2 Oscillator adjusted to its drive needs[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    34. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCSCTL6 &= ~XT2OFF; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Turns on the XT2 oscillator[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    35. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]do[/COLOR][/SIZE][/COLOR][/SIZE][/B][/LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
    36. [/color][/size][/color][/size][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]{
    37. UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG); [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Clear XT2 oscillator fault flag[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    38. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]SFRIFG1 &= ~OFIFG;
    39. }[/LEFT][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (SFRIFG1&OFIFG); [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Test oscillator fault flag[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    40. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Setting up I2C[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    41. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCB1CTL1 |= UCSWRST; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Keep USCI in reset( Enable SW reset)[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    42. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// I2C Master, synchronous mode[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    43. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCB1CTL1 = UCSSEL_2 + UCSWRST; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Selects the SMCLK, keep SW reset[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    44. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCB1BR0 = 120; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// fSCL = SMCLK/12 = ~100kHz[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    45. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCB1BR1 = 0;
    46. UCB1I2CSA = 0x98; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Slave Address is 098h[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    47. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]UCB1CTL1 &= ~UCSWRST; [/LEFT][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Clear SW reset, resume operation[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    48. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]PJOUT &= ~BIT1;
    49. [/LEFT][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (1)
    50. {
    51. PJOUT ^= BIT1;
    52. PTxData = ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]unsigned[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] *)TxData; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// TX array start address[/COLOR][/SIZE][/COLOR][/SIZE][LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    53. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
    54. UCB1CTL1 |= UCTR + UCTXSTT; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// I2C TX, start condition[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    55. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]for[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](i=0;i<1000;i++);
    56. UCB1CTL1 |= UCTXSTP; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Delay required between transaction[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
    57. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]for[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](i=0;i<1000;i++);
    58. }
    59. }
    60.  
    61.  
    62. [/SIZE][/left]

    Thanks in advance!

     
    Last edited by a moderator: Jan 5, 2012
Loading...