Tool/software: Code Composer Studio
I am trying to set up the light sensor on the Educational Boosterpack MKII to display the red LED when the it is receiving no light (covering it with my thumb), however, for some reason it will not work properly. I believe it has something to do with my i2c not being configured properly even though I followed the example on CCS. If anyone can direct me to other helpful examples, or explain to me what I need to change or add, it would be greatly appreciated. The following is my code:
.data
Light_on: .word 0x0001
Temp_high: .word 0x0001
TXData: .char 0xA1,0xB1,0xC1,0xD1
SlaveAddress: .char 0x0A,0x0B,0x0C,0x0D
TXByteCtr: .set R5
SlaveFlag: .set R6
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop here
;-------------------------------------------------------------------------------
SetupGPIO: bis.b #BIT6+BIT7,P1SEL0 ; I2C pins
UnlockGPIO: bic.w #LOCKLPM5,&PM5CTL0 ; Disable the GPIO power-on default
; high-impedance mode to activate
; previously configured port settings
SetupI2C: mov.w #UCSWRST,&UCB0CTLW0 ; put eUSCI_B in reset state
bis.w #UCMODE_3+UCMST+UCSSEL__SMCLK,&UCB0CTLW0 ; I2C master mode, SMCLK
mov.w #0x8,&UCB0BRW ; baudrate = SMCLK / 8
bic.w #UCSWRST,&UCB0CTLW0 ; clear reset register
bis.w #UCTXIE0+UCNACKIE,&UCB0IE ; transmit and NACK interrupt enable
clr.b SlaveFlag ; Initialize SlaveFlag
Light:
mov.w #0,&PM5CTL0 ;Clear lock LPM5 bit
bic.b #00000001b,&P2DIR ;Set P2.0 as input of MSP from light sensor of booster J1.8
bis.b #00000011b,&P4DIR ;Set P4.0 and P4.1 as outputs to booster J1.9 and J1.10
bis.b #00000011b,&P4SEL1 ;Set P4.0 and P4.1 as secondary module i2C function
bic.b #00000011b,&P4SEL0
mov.b #00000010b,&P4OUT ;Pull SCL i2C pin high
mov.b #00000001b,&P4OUT ;Pull SDA i2C pin low
bis.b #00001000b,&P3DIR ;Set P3.3 as output from MSP to provide input for booster Green LED J4.38
bis.b #00001000b,&P3OUT ;Set P3.3 output as high to turn on green LED
bis.b #01000000b,&P2DIR ;Set P2.6 as output from MSP to provide input for booster Red LED J4.39
bis.b #00000001b,&P2IES ;Set interrupt on high-to-low transition of P2.0
bic.b #00000001b,&P2IFG ;Clear any interrupts that happened when changing P2IES
bis.b #00000001b,&P2IE ;Enables P2.0 interrupts
Mainloop:
jmp Mainloop
Port2_ISR:
bic.b #00000001b,&P2IFG ;Clear interrupt flag
bic.b #00001000b,&P3OUT ;set P3.3 output as low (Green LED)
bis.b #01000000b,&P2OUT ;set P2.6 output as high (RED LED)
Light_loop:
cmp.w &P2IN, Light_on
jl Light_loop
cmp.w &P2IN, Light_on
jge if_break
if_break:
bic.b #01000000b,&P2OUT ;set P2.6 output as low (RED LED)
bis.b #00001000b,&P3OUT ;set P3.3 output as high (Green LED)
reti