Ram.c

Go to the documentation of this file.
00001 #include "Ram.h"
00002 
00004 void Ram::writeBytes(uint16_t _addr, unsigned char *_data, unsigned char _length) {
00005 
00006      unsigned char *bytes;
00007      register unsigned char i;
00008      unsigned char slave = 0xA0;
00009      
00010      // send start-condition 
00011      i2c->sendStart();
00012      
00013      // FM24C512 specific addressing
00014      i2c->writeByte( slave ); 
00015      
00016      bytes = (unsigned char*)&_addr;
00017      i2c->writeByte(bytes[0]);
00018      i2c->writeByte(bytes[1]);
00019      
00020      // send data
00021      for (i=0; i<_length; i++) {
00022           i2c->writeByte(_data[i]);
00023      }
00024      
00025      // send stop condition
00026      i2c->sendStop();
00027 }
00028 
00030 void Ram::readBytes(uint16_t _addr, unsigned char *_data, unsigned char _length) {
00031 
00032 
00033      unsigned char *bytes;
00034      register unsigned char i=0;
00035      unsigned char slave = 0xA0;
00036 
00037      // send start-condition 
00038      i2c->sendStart();
00039      
00040      // FM24C512 specific addressing
00041      i2c->writeByte( slave ); 
00042           
00043      // send address
00044      bytes = (unsigned char*)&_addr;
00045      i2c->writeByte(bytes[0]);
00046      i2c->writeByte(bytes[1]);
00047      i2c->sendStart();
00048      i2c->writeByte(0xA1);
00049      
00050      // send data
00051      for (i=0; i<(_length-1); i++) {
00052           _data[i] = i2c->readByte();
00053      }
00054      _data[i] = i2c->readByteWithoutAck();
00055      
00056      
00057      // send stop condition
00058      i2c->sendStop();
00059 }
00060 
00061 
00063 Ram::Ram() {
00064 
00065      //initialize SPI bus
00066      i2c = new I2c();
00067      
00068 }
00069 
00070 
00072 Ram::~Ram() {
00073      delete i2c;
00074 }
00075 
00081 void Ram::enableRAMChip() {
00082 
00083      // Chip-Select auf Low
00084 //   PORTA &= ~((1<<PA6));
00085 //   PORTA |= (1<<PA1) | (1<<PA0);
00086 }
00087 
00093 void Ram::disableRAMChip() {
00094 
00095      // Chip-Select auf High
00096 //   PORTA |= ((1<<PA6));
00097 //   PORTA |= (1<<PA1) | (1<<PA0);
00098 }
00099 
00100 
00102 unsigned char Ram::getRamStatusRegister() {
00103 /*
00104      unsigned char _sr = 0x00;
00105 
00106      // SPI Schnittstelle aktivieren
00107      spi.enableSPI();    
00108 
00109      // RAM Chip aktivieren 
00110      this->enableRAMChip();
00111 
00112      // Kommando schicken
00113      spi.writeData(RAM_RDSR);
00114      
00115      // Antwort auslesen
00116      _sr = spi.readData();
00117      
00118      // RAM Chip wieder deaktivieren
00119      this->disableRAMChip();
00120 
00121      // SPI wieder disabeln 
00122      spi.disableSPI();
00123 
00124      return _sr;*/
00125 }
00126 
00128 void Ram::setRamStatusRegister(unsigned char _sr) {
00129 
00130 //   // SPI Schnittstelle aktivieren
00131 //   spi.enableSPI();
00132 // 
00133 //   // Write-Enable Kommando schicken
00134 //   this->enableRAMChip();
00135 //   spi.writeData(RAM_WREN);
00136 //   this->disableRAMChip();
00137 // 
00138 //   // Write-Status-Register Kommando schicken
00139 //   this->enableRAMChip();
00140 //   spi.writeData(RAM_WRSR);
00141 //   spi.writeData(_sr);
00142 //   this->disableRAMChip();
00143 // 
00144 //   // SPI wieder disabeln 
00145 //   spi.disableSPI();
00146 }
Generated on Fri Oct 8 17:10:07 2010 for Crawling Robot Microcontroller Software by  doxygen 1.6.3