1st attempt at sending a packet

This commit is contained in:
Stefan `Sec` Zehl 2011-07-08 00:39:51 +02:00
parent 821acca753
commit bd4eb20d5e
2 changed files with 61 additions and 4 deletions

View File

@ -62,6 +62,41 @@ void f_recv(void){
};
void f_send(void){
static char ctr=1;
int dx=0;
int dy=8;
uint8_t buf[32];
int status;
int crc;
buf[0]=0x05; // ID
buf[1]=0xEC; // ID
buf[2]=0xff;
buf[3]=0xff; // Send intensity
buf[4]=0x00; // ctr
buf[5]=0x00; // ctr
buf[6]=0x00; // ctr
buf[7]=ctr++; // ctr
buf[8]=0xff;
buf[9]=0xff;
buf[10]=0xff;
buf[11]=0xff;
buf[12]=0xff;
buf[13]=0xff;
crc=crc16(buf,14);
buf[14]=crc & 0xff; // CRC
buf[15]=(crc >>8) & 0xff; // CRC
status=nrf_snd_pkt_crc(16,buf);
dx=DoString(0,dy,"St:"); DoInt(dx,dy,status); dy+=8;
};
void gotoISP(void) {
DoString(0,0,"Enter ISP!");
lcdDisplay(0);
@ -86,12 +121,14 @@ const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
const struct MENU_DEF menu_init = {"F Init", &f_init};
const struct MENU_DEF menu_status = {"F Status", &f_status};
const struct MENU_DEF menu_rcv = {"F Recv", &f_recv};
const struct MENU_DEF menu_snd = {"F Send", &f_send};
const struct MENU_DEF menu_nop = {"---", NULL};
static menuentry menu[] = {
&menu_init,
&menu_status,
&menu_rcv,
&menu_snd,
&menu_nop,
&menu_ISP,
NULL,
@ -214,3 +251,4 @@ void tick_funk(void){
return;
};

View File

@ -45,22 +45,25 @@ void nrf_write_reg(const uint8_t reg, const uint8_t val){
CS_HIGH();
};
void nrf_read_long(const uint8_t reg, int len, uint8_t* data){
void nrf_read_long(const uint8_t cmd, int len, uint8_t* data){
CS_LOW();
xmit_spi(reg);
xmit_spi(cmd);
for(int i=0;i<len;i++)
data[i] = 0x00;
sspSendReceive(0,data,len);
CS_HIGH();
};
void nrf_write_reg_long(const uint8_t reg, int len, uint8_t* data){
void nrf_write_long(const uint8_t cmd, int len, uint8_t* data){
CS_LOW();
xmit_spi(C_W_REGISTER | reg);
xmit_spi(cmd);
sspSend(0,data,len);
CS_HIGH();
};
#define nrf_write_reg_long(reg, len, data) \
nrf_write_long(C_W_REGISTER|reg, len, data)
void nrf_init() {
// Enable SPI correctly
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
@ -129,3 +132,19 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt){
CS_HIGH();
return len;
};
char nrf_snd_pkt_crc(int size, uint8_t * pkt){
nrf_write_reg(R_CONFIG,
R_CONFIG_PWR_UP| // Power on
R_CONFIG_CRCO // 2-byte CRC
);
nrf_write_long(C_W_TX_PAYLOAD,size,pkt);
CE_HIGH();
delayms(10); // Send it. (only needs >10ys, i think)
CE_LOW();
return nrf_cmd_status(C_NOP);
};