реклама на сайте
подробности

 
 
> at45dbxxx и atmel, не могу никак связаться с памятью
kostian296
сообщение Oct 20 2008, 16:03
Сообщение #1


Участник
*

Группа: Новичок
Сообщений: 16
Регистрация: 20-10-08
Пользователь №: 41 074



не работал раньше с флешками.
контроллер tamega168. флешка at45db161su.
кварц 11.059мгц.

void spi_init(void)
{
SPCR = 0x5c; //setup SPI
SPSR = 0x00; //setup SPI
}

CS_ON;
Kod=0x9F; /* manufacture and device id read */
SPDR = Kod; // ?????? ???? ??? ???????? ? ???
while(!(SPSR & 0x80));
M[0]=SPDR;
SPDR = 0xff; // ?????? ???? ??? ???????? ? ???
while(!(SPSR & 0x80));
M[1]=SPDR;

нет ответа от флешки. на этой строке виснет: while(!(SPSR & 0x80));
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
aaarrr
сообщение Oct 20 2008, 16:35
Сообщение #2


Гуру
******

Группа: Свой
Сообщений: 10 713
Регистрация: 11-12-04
Пользователь №: 1 448



Цитата(kostian296 @ Oct 20 2008, 20:29) *
у флешки so - садить на MISO ?
si - на MOSI ?

Да, но это абсолютно не важно, если:
Цитата(kostian296 @ Oct 20 2008, 20:03) *
нет ответа от флешки. на этой строке виснет: while(!(SPSR & 0x80));

вот уж виснуть он не должен никак.
Go to the top of the page
 
+Quote Post
defunct
сообщение Oct 20 2008, 17:10
Сообщение #3


кекс
******

Группа: Свой
Сообщений: 3 825
Регистрация: 17-12-05
Из: Киев
Пользователь №: 12 326



Цитата(aaarrr @ Oct 20 2008, 19:35) *
вот уж виснуть он не должен никак.

Абсолютно точно. А коль уж он виснет на этой строчке, то возможно что-то не так с SS:

When the SPI is configured as a Master (MSTR in SPCR is set), the user can determine the
direction of the SS pin.
If SS is configured as an output, the pin is a general output pin which does not affect the SPI
system. Typically, the pin will be driving the SS pin of the SPI Slave.
If SS is configured as an input, it must be held high to ensure Master SPI operation. If the SS pin
is driven low by peripheral circuitry when the SPI is configured as a Master with the SS pin
defined as an input, the SPI system interprets this as another master selecting the SPI as a
slave and starting to send data to it. To avoid bus contention, the SPI system takes the following
actions: ....


попробуйте проинициализировать SPI и PORTB так:

Код
#define SPI_SCK  PB5
#define SPI_MOSI PB4
#define SPI_MISO PB3
#define SPI_SS   PB2

    // initialize PORTB for SPI
    DDRB |= (1 << SPI_MOSI)|(1 << SPI_SCK)|(1 << SPI_SS);
    DDRB &= ~(1 << SPI_MISO);

    // Enable SPI in mode 3 Master, set clock rate fck/4
    SPCR = (1 << SPE)|(1 <<MSTR)|(1 << CPOL)|(1 << CPHA);
    SPSR = (1 << SPI2X); // 2x rate
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 29th July 2025 - 02:13
Рейтинг@Mail.ru


Страница сгенерированна за 0.02717 секунд с 7
ELECTRONIX ©2004-2016