Adem Bayraktar
/
STM32-NRF-SPI_07112016
A
Fork of SPI_Demo_Nano by
Revision 3:b4887e2837ab, committed 2016-11-14
- Comitter:
- Adembay
- Date:
- Mon Nov 14 14:23:03 2016 +0000
- Parent:
- 2:a644bf386c5a
- Commit message:
- M
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jan 07 02:51:23 2016 +0000 +++ b/main.cpp Mon Nov 14 14:23:03 2016 +0000 @@ -1,102 +1,69 @@ -/* - -Copyright (c) 2012-2014 RedBearLab - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*/ - #include "mbed.h" #include "spi_master.h" - +//# SCK P0_25 +//# MOSI P0_20 +//# MISO P0_22 +//# CS P0_7 DigitalOut spi_cs(P0_7); - SPIClass SPI1(NRF_SPI1); - Serial pc(USBTX, USBRX); -void Flash_Buff_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) +uint8_t i,izin=1; +uint8_t wt_buf[] = "DENEMEE"; +uint8_t rd_buf[7]; +uint32_t x=0; + + +uint8_t DATA_1[50]={0x07,0xdd,0xcc,0xee,0x15,0x23,0x56,0x11,0x33}; + + +void WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) { uint16_t index; - spi_cs = 0; - wait_us(200); - - SPI1.transfer(0x84); - SPI1.transfer(0x00); - SPI1.transfer((uint8_t)(addr>>8)); - SPI1.transfer((uint8_t)addr); + wait_us(20); for(index=0; index<len; index++) { SPI1.transfer(*pbuf); pbuf++; } - wait_us(200); + wait_us(20); spi_cs = 1; } -void Flash_Buff_ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) +void ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) { uint16_t index; spi_cs = 0; - wait_us(200); - - SPI1.transfer(0xD1); - SPI1.transfer(0x00); - SPI1.transfer((uint8_t)(addr>>8)); - SPI1.transfer((uint8_t)addr); + wait_us(5); for(index=0; index<len; index++) { *pbuf = SPI1.transfer(0x00); pbuf++; } - - wait_us(200); spi_cs = 1; } -uint8_t i; -uint8_t wt_buf[7] = {'H','e','l','l', 'o', '\r', '\n'}; -uint8_t rd_buf[7]; - int main(void) { pc.baud(9600); - wait(8); - spi_cs = 1; - pc.printf("SPI Demo Start \r\n"); - - //SPI1.begin(); - SPI1.begin(P0_6, P0_15, P0_29);//SCK, MOSI, MOSI - - wait(1); - Flash_Buff_WriteBytes(0, wt_buf, 7); + SPI1.begin(); //SPI1.begin(P0_6, P0_15, P0_29);//SCK, MOSI, MOSI + pc.printf("SPI Demo Start\r\n"); while(1) { - memset(rd_buf, 0x00, 7); - Flash_Buff_ReadBytes(0, rd_buf, 7); - for(i=0; i<7; i++) - pc.putc(rd_buf[i]); + + WriteBytes(0, DATA_1, sizeof(DATA_1)); + for(i=0; i<sizeof(DATA_1); i++) + { + pc.printf("%02x",DATA_1[i]); + } + pc.printf(" %d \r\n",x); + + wait(1); + + } -} - - - - - - - +} \ No newline at end of file