2013-10-31

MagicBlue LPC1114 Eval Board testing notes























MagicBlue LPC1114 barebone with signal routing board.  The ISP wiring works for one board but not others.  I first supspected that the 3V3 PSU is weak.  But it was 3.28V.  I tried lowered the transfer speed from 115,200 down to 9.600 but still not luck.

.END

Magic Blue LPC1114 Eval Board PSU circuit

























Magic Blue LPC1114 Eval Board PSU circuit

.END

2013-10-30

WheelMan - 劉肇豐

香港新霍金 擬研凌空鍵盤 助殘疾人士輕鬆打字學習 - 蘋果日報 2013年10月30日

http://hk.apple.nextmedia.com/news/art/20131030/18485429

劉肇豐決心延續師兄的精神,以科技改善殘疾人士生活。王子俊攝

靈感源自生活,自幼患肌肉萎縮症的劉肇豐,每次離家盡是不便,決心以科技助同病相憐者重拾生活樂趣。他在理大電子計算學系求學的三年間主攻軟件設計,最新作品針對殘疾人士雙手乏力難用鍵盤,研發以感應器辨識手部動作控制電腦及自動登入系統,應付學習需要。一紙畢業證書未令肇豐停下腳步,他準備攻讀碩士,繼續實踐助人自助的抱負。 

記者:袁樂婷

病魔令肇豐雙手乏力,學習比別人慢,他堅持在輪椅上奮鬥,昨日如願接到學士畢業證書,「頂硬上,最緊要對自己有信心,冇嘢克服唔到」。他與同患肌萎症的「香港霍金」劉曉鋒早於中學時結緣,更同樣師承理大電子計算學系副教授陳峻斌。

設計商場無障礙設施App

曉鋒去年因病離世,以科技改善殘疾人士生活的遺願,今由肇豐延續,「因為每日都面對相同困難,所以感受特別深刻,知道殘疾人士嘅需要」。

他舉例,輪椅使用者出入商場要找無障礙通道,往往如尋寶般困難,「試過問商場職員同保安,佢哋都要周圍問人問一大輪先知,都幾麻煩」,因此設計手機應用程式(App)「Wheelman」,提供不同商場及餐廳的無障礙資訊,並讓輪椅使用者分享經驗,「起碼出到去知道邊啲地方可以入到」。

他也說,殘疾人士雙手不靈活,簡單如登入電腦,也要花長時間逐字輸入密碼,肇豐運用類似八達通的技術,在輪椅上設感應卡,讓他們接近電腦時能自動登入,甚至按各人弱點設定電腦,例如放大字體及調校色彩對比度等;他更以自創軟件配合美國廠商出品的小型感應器,辨識雙手擺動方向,控制揭頁及回答是非題,長遠計劃研發凌空鍵盤,助殘疾人士打字,應付學習需要。

肇豐的作品兩度獲理大「微型基金計劃」創新組大獎,目前仍在研發階段,暫未計劃推出市面。

陳峻斌看好愛徒作品的前景,並指以降低成本為首要之務,「如果買一部電腦5千蚊,但套系統要5萬蚊,咁就冇意思。我哋希望係普遍殘疾人士可以負擔嘅價錢,真正幫到佢哋」。


.END

Dual MCP3208 boards tested OK
































Now I have retested the first MCP3028 board, with A0~3 connected to 2.5V, and
A4~7 to 3V3 / 2.  Again, the results look good.



testBlinkOlimexLed1();
testBlinkLpc1114LedP03();
testOlimex7segmentLed0101();
testMax7219v04(SPI_CHANNEL_0);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_0);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_1);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_2);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_3);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_4);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_5);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_6);

testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_7);

ADC Channel = 0
ADC result hex = fff
ADC result decimal = 4095
ADC result milliVolt = 2489

ADC Channel = 1
ADC result hex = fff
ADC result decimal = 4095
ADC result milliVolt = 2489

ADC Channel = 2
ADC result hex = fff
ADC result decimal = 4095
ADC result milliVolt = 2489

ADC Channel = 3
ADC result hex = fff
ADC result decimal = 4095
ADC result milliVolt = 2489

ADC Channel = 4
ADC result hex = a7f
ADC result decimal = 2687
ADC result milliVolt = 1633

ADC Channel = 5
ADC result hex = a7f
ADC result decimal = 2687
ADC result milliVolt = 1633

ADC Channel = 6
ADC result hex = a7f
ADC result decimal = 2687
ADC result milliVolt = 1633

ADC Channel = 7
ADC result hex = a7f
ADC result decimal = 2687
ADC result milliVolt = 1633

.END

MCP3208 ADC all 8 channels tested OK

Now I am testing all 8 channels in one go.  I connected A0~3 to 3V3/2 and A4~7 to LM385 2.5 (actually 2.47V).  Then I ran the following tests.

 testBlinkOlimexLed1();
testBlinkLpc1114LedP03();
testOlimex7segmentLed0101();
testMax7219v04(SPI_CHANNEL_0);

testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_0);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_1);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_2);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_3);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_4);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_5);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_6);
testMcp3208(SPI_CHANNEL_1, ADC_CHANNEL_7);


And I go the following results.

ADC Channel = 0
ADC result milliVolt = 1655

ADC Channel = 1
ADC result milliVolt = 1658

ADC Channel = 2
ADC result milliVolt = 1655

ADC Channel = 3
ADC result milliVolt = 1655

ADC Channel = 4
ADC result milliVolt = 2488

ADC Channel = 5
ADC result milliVolt = 2482

ADC Channel = 6
ADC result milliVolt = 2489

ADC Channel = 7
ADC result milliVolt = 2482

The results look good.  And I call it a day. 



*** MAX7219 Test v04 - 2013oct30hk1112 ***
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  06 00 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  06 00 00 
RxBuf  ff ea a3 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 0
ADC result hex = aa3
ADC result decimal = 2723
ADC result milliVolt = 1655

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  06 40 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  06 40 00 
RxBuf  ff ea a8 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 1
ADC result hex = aa8
ADC result decimal = 2728
ADC result milliVolt = 1658

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  06 80 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  06 80 00 
RxBuf  ff ea a3 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 2
ADC result hex = aa3
ADC result decimal = 2723
ADC result milliVolt = 1655

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  06 c0 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  06 c0 00 
RxBuf  ff ea a3 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 3
ADC result hex = aa3
ADC result decimal = 2723
ADC result milliVolt = 1655

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  07 00 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  07 00 00 
RxBuf  ff ef fe 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 4
ADC result hex = ffe
ADC result decimal = 4094
ADC result milliVolt = 2488

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  07 40 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  07 40 00 
RxBuf  ff ef f3 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 5
ADC result hex = ff3
ADC result decimal = 4083
ADC result milliVolt = 2482

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  07 80 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  07 80 00 
RxBuf  ff ef ff 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 6
ADC result hex = fff
ADC result decimal = 4095
ADC result milliVolt = 2489

*** End of Test. *** 

*** End of Test. *** 
*** MCP3208 Test - 2013oct27hk0948 ***

*** Tx Rx buffer contents before ADC *** 
Index    0  1   2
TxBuf  07 c0 00 
RxBuf  00 00 00 

*** Tx Rx buffer contents after ADC *** 
Index    0  1   2
TxBuf  07 c0 00 
RxBuf  ff ef f3 

***ADC Results Summary *** 
SPI Channel = 1
ADC Channel = 7
ADC result hex = ff3
ADC result decimal = 4083
ADC result milliVolt = 2482

*** End of Test. *** 

*** End of Test. *** 

.END

MCP3208 board #2 assembly notes





















Now I have assembled another MCP3208 board and going to test it.

.END

高交會 香港優秀軟件展區 - 香港軟件行業協會

第十五屆中國國際高新技術成果交易會暨香港日 香港信息科技業代表團 2013年11月18日

http://www.hksia.hk/2013/web/

把握國家發展大勢 繼續開拓內地市場

內地發展一日千里,可是市場瞬息萬變,要捕捉各個商機,必須好好掌握內地市場脈搏。今年11月18日,香港貿易發展局將聯同香港軟件行業協會舉辦「香港信息科技業代表團」參觀第十五屆中國國際高新技術成果交易會暨香港日。通過參觀當地展覽會、交流活動、研討會等,協助香港信息科技業業界深化對內場市場的了解,強化當地人脈,進一步開拓龐大的內地市場。

第十五屆中國國際高新技術成果交易會(高交會)

深圳高交會將於2013年11月16至21日在深圳會展中心舉行。由中華人民共和國商務部、科學技術部、工業和信息化部、國家發展和改革委員會、教育部、人力資源和社會保障部、農業部、國家知識產權局、中國科學院、中國工程院、深圳市人民政府主辦,深圳市中國國際高新技術成果交易中心(深圳會展中心管理有限責任公司)承辦,中國規模最大、最具影響力的科技類展會。每屆展會參觀人數超過50萬人,產品與技術交易額超過130億美元。今年高交會以「堅持創新驅動發展,提高經濟增長質量」為主題,預計總展覽面積超過11萬平方米。

立即參加 把握機遇

通過是次考察團,你將可以:

了解當地市場:

參觀當地展覽會及出席論壇,了解當地最新科技政策、市場發展及行業最新動態

擴展商業網絡:

出席各項交流活動,和當地業界人士及潛在客戶會面,擴展您的商業網絡,發掘更多商機

暫定行程:

08:00 九龍塘集合

08:15-10:00 直通巴往深圳

10:15-11:45 參觀高交會及「香港優秀軟件展區

12:00-14:00 香港信息科技業深圳交流午宴

14:30-17:30 深港澳信息科技論壇

18:00-20:30 深港澳信息科技交流晚宴

20:45 直通巴回港

2013深圳高交會「香港優秀軟件展館」- 參展商名單公佈


参展期:11月16-18日 参展期:11月19-21日
序号 公司名称 序号 公司名称

1 多莱宝数码媒体软件公司                  4 世通系统有限公司
2 标奥电子商务有限公司                  6 奥玛物流服务有限公司
3 傲讯全通科技有限公司                 10 Astrum   (H.K) Limited
5 科施工作流有限公司                         12 兆兴科域有限公司
7 江波龙科技(香港)有限公司         13 昆仲科技有限公司
8 香港尖端网页设计有限公司         15 通正科技有限公司
9 云深系统有限公司                         16 社群网络有限公司
11 欣扬应用服务有限公司                 17 智通环球电讯有限公司
14 权智有限公司                                 18 昊豆有限公司
20 华讯站有限公司                                 19 太平洋商业网络有限公司
24 赛美斯系统有限公司                         21 博博熊教育有限公司
25 舆情服务(香港)有限公司                 22 K-Matrix Digital Intelligence Limited
26 慧讯软件有限公司                         23 德修在线有限公司
27 皓华(香港)网络通讯有限公司 28 艾普阳(香港)有限公司
29 永泰信息技术服务有限公司         31 八达马科技(香港)有限公司
30 键次方通讯有限公司                         33 思齐软件有限公司
32 志鸿科技国际(香港)有限公司 35 AMC Workshop Ltd.
34 博克国际(香港)有限公司         37 四专科技有限公司
36 汇流媒体有限公司                         39 中国梅亿(香港)新能源控股集团有限公司
38 亚势系统有限公司                         40 中包技术有限公司


.END

2013-10-29

Mini USB plug pinout


























Mini USB plug pinout

.END

Dual Olimex LPC1114 Eval Board testing notes

























Now both Olimex LPC1114 evaluation boards have the following connected.

1. Signal routing board, with P03 LED.

2. HC599 based 1-digit/4-digit 7-segment LED module.

3. MAX9219 based 4-digit 7-segment LED.

Both boards run the following test OK.

testBlinkOlimexLed1();
testBlinkLpc1114LedP03();
testOlimex7segmentLed0101();
testMax7219(SPI_CHANNEL_0); // testMax7219(SPI_CHANNEL_1);

.END

HC599 burning out problem
























So far I have burnt out 3 HC599 ICs.  At first I thought the ICs are bad quality or factory rejects.  But now I guess that I might have over driven the ICs.  I skimmed through the datasheet and have the impression that the output can drive at least 3mA, and up to 6mA, but not sure if it is OK to drive all segments at the same time non multiplexingly.  Anyway, I am too lazy to use buffers to off load the ICs.  Instead I am using a heat sink for one of the ICs.  If the other ICs  burn out sooner or later, then perhaps I should redesign the circuit, or give up HC599 and use MAX7219 instead.  However, one good thing about HC595 is that there is no limit on the number of digits, while MAX7219 only allows 8, if I use the fully assembled module which has no lead out for the MAX7219 serial output.

.END

2013-10-28

Testing HC595 based 4 digit 7-segment LED module


























Now I have tested another serial device, the 4 digit 7-segment LED using HC595.

 // *** Olimex tests - 2013oct28hkt2129 ***
testBlinkOlimexLed1();
testBlinkLpc1114LedP03();
testOlimex7segmentLed0101();
testMax7219(SPI_CHANNEL_0);
// testMax7219(SPI_CHANNEL_1);

.END

Incremental testing and pair program/system development notes

























Now I have assembled and tested one more MAX729 4-digit 7-segment LED module and two sets of SPI0/SPI1 cables to do pair system development.

.END

Agile Myths by V Tasheva

Agile Myths - October 23, 2013 by Vesselina Tasheva

http://www.telerik.com/agile-project-management-tools/blogs/13-10-23/the-truth-about-agile-top-30-agile-myths--busted.aspx

Agile is not suitable for fixed bid projects

Before looking at this myth, it’s important to define “Fixed bid projects”. Does this mean fixed scope, schedule, and cost? History has proven that software projects of any significance in size or complexity cannot be accurately estimated well. What is more, according to CHAOS reports 24% of all projects fail and 44% are significantly challenged. Regardless of the project management methodology, attempting to fix all three does not have a high probability of success. Something has to give – whether it’s adding resources, cutting scope, or moving the delivery date.

As described in the myth “Agile Projects don’t provide Budget Estimates”, agile teams fix the cost, fix the date, and vary the scope. The onus is on the Product Owner to make sure the requirements are not only prioritized correct, but ordered correctly. The team will deliver the highest priority items in the order that they are specified in the product backlog. The lowest priority (and last in the order) items usually turn out to be superfluous, and never need to be developed anyway.

Agile Development is Not Predictable

This myth is closely related to the Agility Means No Commitments. What is more predictable?

Code that is tested and delivered every two weeks, teams that are communicating their status every day (through standups, burn down charts, and various other mechanisms), and requirements that are constantly being groomed and updated.

- or -

Code that doesn’t get tested until the end of a 6/9/12 month project cycle, teams that go dark for months at a time, not reporting status until the end of the construction phase, a requirements document that never gets updated because the change request process is too difficult to manage.

Successful Agile teams bring predictability to software development because every step of the way they are communicating, deploying real code, and adapting to change (and keeping the documentation current). Every two weeks, they will release a set of features that they stated two weeks prior that they were going to work on. They met the expectations and delivered on their predictions.

Are you interested in finding the whole truth about Agile?

In the 11 years since the Agile Manifesto was created, the adoption of agile concepts has continued to grow. This growth has been so significant that Gartner has declared that “agile is now mainstream”.

Along with this growth in adoption and exploration of agile, the number of agile myths has grown as well.

...

.END

XYDZ 0.96" OLED


























XYDZ 0.96" SPI OLED (RMB29)

.END

Max7219 Initial power up problem

Max7219 Initial Power-Up [from datasheet]

On initial power-up, all control registers are reset, the display is blanked, and the MAX7219/MAX7221 enter shutdown mode.

Program the display driver prior to display use. Otherwise, it will initially be set to scan one digit, it will not decode data in the data registers, and the intensity register will be set to its minimum value.


The MAX7219 LED display controller – real or fake? Posted on 16 May 2013

http://tronixstuff.com/2013/05/16/the-max7219-led-display-controller-real-or-fake/

.END

2013-10-27

Max7912 4-digit 7-segment LED function refactoring notes

// ***********************************************************************
// sled050.h 2013oct27hk1425
// ***********************************************************************

#include "spi050.h"

void max7219v03(uint8_t spiChannelNumber) // 2013oct23hkt1315
{
    // *** Print project title ***********************************************
printf("*** MAX7219 Test - 2013oct27hk1357 ***\n\n");

// *** Setup MAX7219 digit control register buffer ***********************
// Digit control register buffer
#define BUFFER_SIZE 2
#define ADDRESS_INDEX 0
#define DATA_INDEX 1

uint8_t digitControlRegisterBuffer[BUFFER_SIZE];
uint8_t dummyReceiveBuffer[BUFFER_SIZE];

setupSpi051(spiChannelNumber);

    // Setup xferConfig
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = (void*)digitControlRegisterBuffer;
    xferConfig.rx_data = (void*)dummyReceiveBuffer;
    xferConfig.length = BUFFER_SIZE;

// *** Setup Max7219 digit and control ***********************************
    // Register addresses
#define NO_OP_ADDR 0x00
#define DIGIT_0_ADDR 0x01
    #define DIGIT_1_ADDR 0x02
#define DIGIT_2_ADDR 0x03
#define DIGIT_3_ADDR 0x04
#define DIGIT_4_ADDR 0x05
#define DIGIT_5_ADDR 0x06
#define DIGIT_6_ADDR 0x07
#define DIGIT_7_ADDR 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY       0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define SHUTDOWN_ADDR   0x0c
#define DISPLAY_TEST     0x0f

// Control byte
#define SHUTDOWN_MODE          0x00
#define NORMAL_OPERATION_MODE  0x01
    #define CODE_B_DECODE_ALL_BITS 0xff
    #define DISPLAY_8_DIGITS       0x07

#define DIGIT_0_DATA 0
#define DIGIT_1_DATA 1
    #define DIGIT_2_DATA 2
    #define DIGIT_3_DATA 3
    #define DIGIT_4_DATA 4
#define DIGIT_5_DATA 5
#define DIGIT_6_DATA 6
#define DIGIT_7_DATA 7
#define DIGIT_8_DATA 8
#define DIGIT_9_DATA 9

    while (1)
        {
    writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SHUTDOWN_ADDR, SHUTDOWN_MODE);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        delayTime(ONE_SECOND);

        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DECODE_MODE_ADDR, \
                                       CODE_B_DECODE_ALL_BITS);
        SpiWriteRead050(xferConfig, spiChannelNumber);

        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SCAN_LIMIT_ADDR, DISPLAY_8_DIGITS);
        SpiWriteRead050(xferConfig, spiChannelNumber);

        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_0_ADDR, DIGIT_1_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_1_ADDR, DIGIT_1_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_2_ADDR, DIGIT_2_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_3_ADDR, DIGIT_3_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_4_ADDR, DIGIT_4_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_5_ADDR, DIGIT_5_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_6_ADDR, DIGIT_6_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, DIGIT_7_ADDR, DIGIT_8_DATA);
        SpiWriteRead050(xferConfig, spiChannelNumber);

        writeSegmentLedCommandToBuffer(digitControlRegisterBuffer, SHUTDOWN_ADDR, \
                                       NORMAL_OPERATION_MODE);
        SpiWriteRead050(xferConfig, spiChannelNumber);
        delayTime(ONE_SECOND);
        }
}

void writeSegmentLedCommandToBuffer(uint8_t digitControlRegisterBuffer[BUFFER_SIZE], \
                           uint8_t commandRegisterAddress, uint8_t command)
{
digitControlRegisterBuffer[ADDRESS_INDEX] = commandRegisterAddress;
digitControlRegisterBuffer[DATA_INDEX] = command;
}

// ***********************************************************************
// End
// ***********************************************************************



// ***********************************************************************
// spi050.h 2013oct26hk1611
// ***********************************************************************

#include "gpio050.h"
#include "led050.h"
#include "lpc11xx_ssp.h"
#include "semihosting.h"
#include "stdio.h"
#include "config050.h"

#ifndef SPI_HEADER_SEEN
#define SPI_HEADER_SEEN

// *** SPI Functions ***

#define SPI_CHANNEL_0 0
#define SPI_CHANNEL_1 1

void setupSpi051(int spiChannelNumber)
{
if (spiChannelNumber == 0)
{
// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);

// Reset SSP0 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, DISABLE);
SYSCON_SetSPI0ClockDiv(10);

// Assign GPIO pins for SPI
SSP_SSP0PinsInit(SCK0_PIO0_6, DISABLE); // Select P06, disable

// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);

// Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);

// Setup Ssel0
setupGpioPinOutputLow050(PortPinArraySsel0);
}
else // (if spiChannelNumber == 1)
{
// Enable SSP1 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP1, ENABLE);

// Reset SSP1 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, DISABLE);
SYSCON_SetSPI1ClockDiv(10);

// No need to assign GPIO pins for SPI1, just disable
SSP_SSP1PinsInit(DISABLE); // disable SSEL

// IOCON_SetPinFunc(IOCON_PIO2_2, PIO2_2_FUN_MISO1);
// IOCON_SetPinFunc(IOCON_PIO2_3, PIO2_3_FUN_PIO_MOSI1);
// IOCON_SetPinFunc(IOCON_PIO2_1, PIO2_1_FUN_SCK1);
// if(useSSEL == ENABLE) {
        //    IOCON_SetPinFunc(IOCON_PIO2_0, PIO2_0_FUN_SSEL1);

// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP1, &SSP_ConfigStruct);

// Enable SSP1 peripheral
SSP_Cmd(LPC_SSP1, ENABLE);

// Setup Ssel1
setupGpioPinOutputLow050(PortPinArraySsel1);
}
}

void setupXferConfig(SSP_DATA_SETUP_Type *xferConfigPointer, uint8_t digitControlRegisterBuffer[], \
            uint8_t dummyReceiveBuffer[], uint8_t bufferSize)
{
    xferConfigPointer->tx_data = digitControlRegisterBuffer;
    xferConfigPointer->rx_data = dummyReceiveBuffer;
    xferConfigPointer->length = bufferSize;
 }

void SpiWriteRead050(SSP_DATA_SETUP_Type xferConfig, int spiChannelNumber)
{
if (spiChannelNumber == 0)
{
setGpioDataPinLow01(PortPinArraySsel0);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(PortPinArraySsel0);
}
else // (spiChannelNumber == 1)
{
setGpioDataPinLow01(PortPinArraySsel1);
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(PortPinArraySsel1);
}
}

#endif /* SPI_HEADER_SEEN */

// ***********************************************************************
// End
// ***********************************************************************




.END