Program Nordic nRF24LU1+ chips using SPI.

Dependencies:   mbed

Committer:
mux
Date:
Sun Mar 13 11:30:09 2011 +0000
Revision:
0:f9a5ac1b59f7
1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mux 0:f9a5ac1b59f7 1 /**
mux 0:f9a5ac1b59f7 2 * Copyright (c) 2011 Ibrahim Abd Elkader
mux 0:f9a5ac1b59f7 3 * Permission is hereby granted, free of charge, to any person obtaining a copy
mux 0:f9a5ac1b59f7 4 * of this software and associated documentation files (the "Software"), to deal
mux 0:f9a5ac1b59f7 5 * in the Software without restriction, including without limitation the rights
mux 0:f9a5ac1b59f7 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mux 0:f9a5ac1b59f7 7 * copies of the Software, and to permit persons to whom the Software is
mux 0:f9a5ac1b59f7 8 * furnished to do so, subject to the following conditions:
mux 0:f9a5ac1b59f7 9 *
mux 0:f9a5ac1b59f7 10 * The above copyright notice and this permission notice shall be included in
mux 0:f9a5ac1b59f7 11 * all copies or substantial portions of the Software.
mux 0:f9a5ac1b59f7 12 *
mux 0:f9a5ac1b59f7 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mux 0:f9a5ac1b59f7 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mux 0:f9a5ac1b59f7 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mux 0:f9a5ac1b59f7 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mux 0:f9a5ac1b59f7 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mux 0:f9a5ac1b59f7 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mux 0:f9a5ac1b59f7 19 * THE SOFTWARE.
mux 0:f9a5ac1b59f7 20 *
mux 0:f9a5ac1b59f7 21 * Program Nordic nRF24LU1+ chips using SPI.
mux 0:f9a5ac1b59f7 22 * Instructions:
mux 0:f9a5ac1b59f7 23 * 1)convert the ihx to binary using objcopy like this:
mux 0:f9a5ac1b59f7 24 * objcopy --gap-fill 255 -Iihex -O binary nrf.ihx nrf.bin
mux 0:f9a5ac1b59f7 25 * 2)copy nrf.bin to MBED flash
mux 0:f9a5ac1b59f7 26 * 3)copy nrflash to MBED flash
mux 0:f9a5ac1b59f7 27 * 4)reset the MBED
mux 0:f9a5ac1b59f7 28 **/
mux 0:f9a5ac1b59f7 29 #include <nrflash.h>
mux 0:f9a5ac1b59f7 30 NRFlash nrflash(p11, p12, p13, p14, p15, p16); //mosi, miso, sck, ssel, prog, reset
mux 0:f9a5ac1b59f7 31 LocalFileSystem local("local");
mux 0:f9a5ac1b59f7 32
mux 0:f9a5ac1b59f7 33 int main()
mux 0:f9a5ac1b59f7 34 {
mux 0:f9a5ac1b59f7 35 nrflash.enable_programming();
mux 0:f9a5ac1b59f7 36
mux 0:f9a5ac1b59f7 37 printf("FSR: %d\n", nrflash.read_fsr());
mux 0:f9a5ac1b59f7 38 printf("erasing flash...\n");
mux 0:f9a5ac1b59f7 39 nrflash.erase_flash();
mux 0:f9a5ac1b59f7 40
mux 0:f9a5ac1b59f7 41 printf("flashing...\n");
mux 0:f9a5ac1b59f7 42 nrflash.write_flash("/local/nrf.bin");
mux 0:f9a5ac1b59f7 43
mux 0:f9a5ac1b59f7 44 printf("saving flash...\n");
mux 0:f9a5ac1b59f7 45 nrflash.read_flash("/local/flash.bin");
mux 0:f9a5ac1b59f7 46 printf("all done...\n");
mux 0:f9a5ac1b59f7 47
mux 0:f9a5ac1b59f7 48 nrflash.disable_programming();
mux 0:f9a5ac1b59f7 49 nrflash.reset();
mux 0:f9a5ac1b59f7 50
mux 0:f9a5ac1b59f7 51 return 0;
mux 0:f9a5ac1b59f7 52 }