S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...
S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...
S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
C:\Documents and Settings\Gerardo\My Documents\Work\SM (MIT)\Thesis\Code\Firmware\I2C_Master.s43<br />
C:\Documents and Settings\Gerardo\My Documents\Work\SM (MIT)\Thesis\Code\Firmware\I2C_Master.s43<br />
//INITIALIZE PORTS<br />
BIS.B #0FFh, &P2OUT ; Set all pins to 1<br />
BIS.B #RD_+WR+SI_WU, &P2DIR ; Set P2 directions<br />
BIS.B #08h, &P2IES ; Interrupt generated with negative transition1<br />
BIS.B #08h, &P2IE ; Activate RD interrupt<br />
MOV.B #0FEh, &P4OUT ; Turn off LED's<br />
BIS.B #07h, &P4DIR ; Set as outputs<br />
//INITIALIZE I2C PORT<br />
BIS.B #70h, P5SEL<br />
BIS.B #0Ah,&P3SEL ; Select I2C pins<br />
BIS.B #I2C+SYNC,&U0CTL ; Recommended init procedure<br />
BIC.B #I2CEN,&U0CTL ; Recommended init procedure<br />
BIS.B #XA,&U0CTL ; Recommended init procedure<br />
BIS.B #I2CSSEL0,&I2CTCTL ; ACLK<br />
MOV.B #7, I2CSCLH ; Set Baud Rate to 400Khz<br />
MOV.B #7, I2CSCLL ; Set Baud Rate to 400Khz<br />
BIS.B #I2CEN,&U0CTL ; Enable I2C<br />
//INITIALIZE VARIABLES<br />
MOV.B #0, I2CFlags<br />
MOV.W #0, USBBufPtr<br />
MOV.B #0, fileFlag<br />
MOV.W #130, R10<br />
CALL #DELAY<br />
MOV.B #0FFh, &P4OUT<br />
//CALL #I2C_RESET<br />
EINT<br />
MainLoop ; Wait here until a code file is transfered<br />
BIT.B #80h, I2CFlags ; Is sampling on?<br />
JNC MainLoop ; Nope, don't do anything<br />
#include "msp430x16x.h"<br />
#define RD_ (0x0001)<br />
#define WR (0x0002)<br />
#define TXE_ (0x0004)<br />
#define RXF_ (0x0008)<br />
#define SI_WU (0x0010)<br />
#define PWREN_ (0x0020)<br />
#define MAX_CODE_SIZE (0x1000)<br />
#define REFLASH_INST (0xA0)<br />
#define RESET_BRAIN_INST (0xA2)<br />
#define RESET_SKIN_INST (0xA4)<br />
#define EXECUTE_CODE_INST (0xA6)<br />
#define REFLASH_DEV_INST (0xA8)<br />
#define RESET_DEV_INST (0xAA)<br />
#define START_SAMPLING_INST (0xAC)<br />
#define STOP_SAMPLING_INST (0xAE)<br />
#define I2C_BRAIN_ADDRESS (0x0100)<br />
#define DATA_BYTES (2)<br />
;_______________________________________________________________________<br />
; Variables<br />
;_______________________________________________________________________<br />
;RAM VARIABLES<br />
ORG 1140h<br />
USBBuf DS MAX_CODE_SIZE<br />
USBBufPtr DS 2<br />
nBytes DS 2<br />
Address DS 2<br />
DataPacket DS 18<br />
fileFlag DS 1<br />
fileStatus DS 1<br />
I2CFlags DS 1<br />
BIC.B #I2CEN,&U0CTL ; Reconfigure I2C<br />
BIS.B #XA,&U0CTL ; Reconfigure I2C<br />
BIC.B #I2CRM,&I2CTCTL ; deactivate Repeat Mode<br />
MOV.B #DATA_BYTES, &I2CNDAT ; Read n bytes<br />
BIC.B #I2CTRX, I2CTCTL ; Read bytes<br />
BIS.B #I2CEN,&U0CTL ; Recommended init procedure<br />
BIS.B #MST,&U0CTL ; Master mode<br />
//MOV #272, Address ; Last node in network<br />
;------------------------------------------------------------------------------<br />
ORG 08000h ; Progam Start<br />
;------------------------------------------------------------------------------<br />
RESET<br />
MOV.W #1130h,SP ; Initialize 'x1x9 stackpointer<br />
//STOP WATCHDOG<br />
MOV.W #WDTPW+WDTHOLD, &WDTCTL ; stop watchdog<br />
//Read sensor info from node X<br />
ReadNode<br />
MOV Address, &I2CSA<br />
CLR R6<br />
MOV #DATA_BYTES, nBytes<br />
BIS.B #I2CSTT+I2CSTP,&I2CTCTL ; Initiate transfer<br />
ReadByte<br />
MOV #0200h, R10 ; Timeout for reception<br />
CALL #I2C_GET_BYTE ; Get byte<br />
CALL #USB_SEND ; Send it through USB<br />
//MOV.B R5, DataPacket(R6) ; Save byte<br />
INC R6<br />
DEC.B nBytes<br />
JNZ ReadByte<br />
//MOV #400, R10<br />
//CALL #DELAY<br />
//INITIALIZE SVS<br />
MOV.B #060h+PORON,&SVSCTL ; SVS POR enabled @ 2.6V<br />
//INITIALIZE CRYSTAL (8.000 MHZ)<br />
BIC #OSCOFF,SR ; Turn on osc.<br />
BIS.B #XTS, &BCSCTL1 ; LFXTL high-freq mode<br />
L1 ; wait for crystal to stabilize<br />
BIC.B #OFIFG,&IFG1 ; Clear OFIFG<br />
MOV #0FFh,R15 ; Delay<br />
L2<br />
DEC R15<br />
JNZ L2<br />
BIT.B #OFIFG,&IFG1 ; Re–test OFIFG<br />
JNZ L1 ; Repeat test if needed<br />
BIS.B #SELM0+SELM1,&BCSCTL2 ; Select XT1 as source for MCLK<br />
BIS.B #SELS, &BCSCTL2 ; select XT1CLK as source for SMCLK<br />
Page 2 of 8<br />
Page 1 of 8