// Menu file TU480A.MNU for testing SPI - master mode // // Connections :- // // CN3 // 2 SCK // 3 /SS // 4 MOSI // 6 MISO // 7 /IRQ // // Use LEFT and RIGHT touch keys to adjust a U8 value and send to slave module // On falling edge of /IRQ send dummy value to slave to receive / display byte LIB(LeftImage, "SDHC/minus.bmp"); LIB(RightImage, "SDHC/plus.bmp"); LIB(Ascii, "SDHC/asc_24.fnt"); LIB(Ascii2, "SDHC/asc_16b.fnt"); STYLE( pagestyle, Page ) { back = Black; } STYLE( textstyle, Text ) { font = Ascii; col = White; curRel = CC; } STYLE( textstyle2, Text ) { font = Ascii2; col = White; curRel = CC; } STYLE( imgstyle, Image ) { curRel = CC; } STYLE( drawstyle, Draw ) { type = box; col = White; maxX = 480;maxY = 272; } STYLE( keystyle, Key ) { type = touch; action = D; delay = 500; repeat = 100; } VAR(val, 0, U8); VAR(getval, 0, U8); // setup /SS (output, K25) and /IRQ (input, K28) lines SETUP(KEYIO) { active = \\12000000; inp = \\10000000; trig = \\10000000; edge = \\00000000; } // setup /IRQ interrupt INT(i, K28, get); // setup SPI interface SETUP(SPI) { active = M; // master mode = LR; // idle LOW, rising edge speed = 1000; // 1Mbps dummy = \\00; end = \\ff; rxi = Y; txi = Y; encode = sd; } // SS high LOAD(K25, 1); PAGE(page1,pagestyle) { // title POSN(240, 15); TEXT(title, "Master", textstyle); // TX box POSN(240, 86); DRAW(txb, 170, 80, drawstyle); POSN(169, 55); TEXT(ttx, "TX", textstyle2); // left arrow key POSN(180,86); IMG(left1,LeftImage,imgstyle); KEY(key1,f1,20,20,keystyle); // value to send POSN(240,86); TEXT(text1,"0",textstyle); // right arrow key POSN(300,86); IMG(right1,RightImage,imgstyle); KEY(key2,f2,20,20,keystyle); // RX box POSN(240, 186); DRAW(txbr, 170, 80, drawstyle); POSN(169, 155); TEXT(trx, "RX", textstyle2); // value read from slave POSN(240,186); TEXT(textr,"",textstyle); } FUNC(get) { // SS low LOAD(K25, 0); WAIT(1); // send dummy to slave / read data LOAD(SPI, \\00); WAIT(1); // SS high LOAD(K25, 1); // fetch and display read value LOAD(getval, SPI); TEXT(textr, getval);; } FUNC(f1) { CALC(val, val, 1, "-"); TEXT(text1, val);; // SS low LOAD(K25, 0); WAIT(1); // send value to slave LOAD(SPI, val); WAIT(1); // SS high LOAD(K25, 1); } FUNC(f2) { CALC(val, val, 1, "+"); TEXT(text1, val);; // SS low LOAD(K25, 0); WAIT(1); // send value to slave LOAD(SPI, val); WAIT(1); // SS high LOAD(K25, 1); } SHOW(page1);