?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

http://www.jkelec.co.kr/img/parts/sd_atmega2560.html



1. Atmega2560 Rabbit 개발보드와 연결 실험

(1) Atmega2560 Rabbit 개발보드와 SPI 인터페이스로 연결 합니다. 

전원은 3.3V/5V 모두 사용가능 합니다. 

(2) 제어 소스(ATMEGA2560 Avrstudio 4.14 Build589 프로젝트 소스 다운로드 )

FAT32형식의 SD메모리의 디렉토리와 파일을 읽어서 UART를 통해서 Display 해주는 예제 입니다. 

SPI_SCK_PIN_NO --> PB1
SPI_MOSI_PIN_NO --> PB2
SPI_MISO_PIN_NO --> PB3
SPI_CS_PIN_NO --> PB0



#include "hw_config.h"
#include "led.h"
#include "uart.h"
#include "mmc_sd.h"
#include "diskio.h"
#include "ff.h"

static FATFS fs;            // Work area (file system object) for logical drive
static char path[20] = {""};
static DIR dirs;
static FILINFO finfo;

void sd_file_list(void)
{
  u32 sd_size;
  char tx_data[16];


  if( disk_initialize(0) == 0 )
    usart0_puts("\r\nsd initialize success.\r\n");
  else
    usart0_puts("\r\nsd initialize failed.\r\n");

#if 1


  f_mount(0,&fs);

  usart0_puts("\r\nf_mount()\r\n");

  if (f_opendir (&dirs, path) == FR_OK)
    {
      usart0_puts("\r\nf_opendir()\r\n");
        while (f_readdir (&dirs, &finfo) == FR_OK)
      {
        usart0_puts("\r\nf_readdir()\r\n");
      usart0_format_puts ("\r\n%s", finfo.fname);
          if (!(finfo.fattrib & AM_DIR))
          {

              if (!finfo.fname[0])
              {
                usart0_puts("\r\nfinfo.fname\r\n");
                  break;

        }
              usart0_format_puts ("\r\n%s", finfo.fname);
          }
        }



  }
#endif
  sd_size = SD_GetCapacity();

#ifdef USE_AVR_STUDIO
  ultoa( sd_size, tx_data, 10);
#else
  ultoa( tx_data, sd_size, 10);
#endif
  usart0_format_puts("\r\nCapacity=%s Bytes\r\n", tx_data);
}

void main(void)
{

  CLI();  // all interrupt disable

  bsp_led_gpio_init();

#if 1
  bsp_usart0_gpio_init();


  if( F_CPU == 8000000UL )
  {
    bsp_usart0_init(F_CPU, EBaud38400, EData8, EParNone, EStop1, FALSE );
  }
  else
  {
    bsp_usart0_init(F_CPU, EBaud115200, EData8, EParNone, EStop1, FALSE );
  }

  init_usart0_buffer();

  bsp_usart0_interrupt_enable();

  SEI();  // all interrupt enable

  bsp_led_core_on(ledUserCore);

  sd_file_list();
#endif

  //bsp_led_core_on(ledUserCore);

  while( 1 )
  {
    _delay_ms(10);
  }

  return;
}



Simple Audio Player 예제


https://www.arduino.cc/en/Tutorial/SimpleAudioPlayer


/*
  Simple Audio Player

 Demonstrates the use of the Audio library for the Arduino Due

 Hardware required :
 * Arduino shield with a SD card on CS4
 * A sound file named "test.wav" in the root directory of the SD card
 * An audio amplifier to connect to the DAC0 and ground
 * A speaker to connect to the audio amplifier

 Original by Massimo Banzi September 20, 2012
 Modified by Scott Fitzgerald October 19, 2012
 Modified by Arturo Guadalupi December 18, 2015

 This example code is in the public domain

 http://www.arduino.cc/en/Tutorial/SimpleAudioPlayer

*/

#include <SD.h>
#include <SPI.h>
#include <Audio.h>

void setup() {
  // debug output at 9600 baud
  Serial.begin(9600);

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println(" failed!");
    while(true);
  }
  Serial.println(" done.");
  // hi-speed SPI transfers

  // 44100kHz stereo => 88200 sample rate
  // 100 mSec of prebuffering.
  Audio.begin(88200, 100);
}

void loop() {
  int count = 0;

  // open wave file from sdcard
  File myFile = SD.open("test.wav");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

  const int S = 1024; // Number of samples to read in block
  short buffer[S];

  Serial.print("Playing");
  // until the file is not finished
  while (myFile.available()) {
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));

    // Prepare samples
    int volume = 1024;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

    // Every 100 block print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }
  }
  myFile.close();

  Serial.println("End of file. Thank you for listening!");
  while (true) ;
}



Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
506 C 힙 정렬 Heap Sort file 2005.08.10 38230 0
505 Pi 회로부품 메모 1 secret 2019.08.09 1 0
504 JAVA 현재시간 구하기 2015.10.21 7750 0
503 MFC 현재디렉토리의 파일리스트들을 알아오는 클래스 CFindFile 2008.05.07 62458 0
502 MFC 현재 실행된 어플리케이션의 디렉토리 적용하기 2008.05.07 39893 0
501 일반 프리미어 프로 Premier Pro secret 2022.02.04 0 0
500 MFC 프로젝트 Resource에서 파일로 저장하는 방법 2010.11.01 34684 0
499 LINUX 프로세스를 이름으로 단번에 종료하기 2017.06.07 8570 0
498 MFC 폴더가 존재하는 지 확인하고, 없으면 만드는 함수 2010.02.01 58378 0
497 Pi 포토커플러 Photo Coupler 특징, 종류, 출력, 구조, 동작 원리, 파라미터 2019.01.03 25946 0
496 LINUX 패치 파일 만들기와 적용하기 (patch, diff) 2 2012.10.22 35805 0
495 MFC 파일 읽기 전용 해제 및 설정 2009.09.11 54202 0
494 PHP 파일 데이터 저장하고 불러오기(파일 입출력) 2015.09.30 8394 0
493 Pi 파이썬 코드를 이용한 파이카메라 제어 2018.04.24 10332 0
492 C# 트레이 아이콘 만들기 2013.08.05 13125 0
목록
Board Pagination ‹ Prev 1 2 3 4 5 6 7 8 9 10 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5